FrameLayout+底部按钮
来源:互联网 发布:淘宝上韩国运动品牌 编辑:程序博客网 时间:2024/05/29 04:45
1.在drawable下创建selector类
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@color/colorBlue"></item> <item android:state_checked="false" android:drawable="@color/colorBlack"></item></selector>
2.在values->color文件下写两个颜色
<color name="colorBlue">#0ff</color><color name="colorBlack">#000</color>
3.主布局布局文件
<!--主布局--><LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout android:id="@+id/fl" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="9"></FrameLayout> <RadioGroup android:id="@+id/rg" android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" android:layout_weight="1"> <RadioButton android:id="@+id/rb1" android:layout_width="match_parent" android:layout_height="match_parent" android:button="@null" android:layout_weight="1" android:checked="true" android:textColor="#fff" android:background="@drawable/selector" android:text="" android:gravity="center" android:textSize="25sp"/> <RadioButton android:id="@+id/rb2" android:layout_width="match_parent" android:layout_height="match_parent" android:button="@null" android:layout_weight="1" android:textColor="#fff" android:background="@drawable/selector" android:text="" android:gravity="center" android:textSize="25sp"/> <RadioButton android:id="@+id/rb3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:button="@null" android:gravity="center" android:textColor="#fff" android:background="@drawable/selector" android:text="" android:textSize="25sp" /> <RadioButton android:id="@+id/rb4" android:layout_width="match_parent" android:layout_height="match_parent" android:button="@null" android:layout_weight="1" android:textColor="#fff" android:background="@drawable/selector" android:text="我的" android:gravity="center" android:textSize="25sp"/> </RadioGroup></LinearLayout>
4.写n个fragment.xml和Fragment.java
......
5.MainActivity类
public class MainActivity extends AppCompatActivity { private FrameLayout fl; private RadioGroup rg; private Fragment01 fragment01; private Fragment02 fragment02; private Fragment03 fragment03; private Fragment04 fragment04; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化组件 fl = (FrameLayout) findViewById(R.id.fl); rg = (RadioGroup) findViewById(R.id.rg); //获取Fragment fragment01 = new Fragment01(); fragment02 = new Fragment02(); fragment03 = new Fragment03(); fragment04 = new Fragment04(); //开启管理者,添加Fragment FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(R.id.fl,fragment01); transaction.add(R.id.fl,fragment02); transaction.add(R.id.fl,fragment03); transaction.add(R.id.fl,fragment04); //进行显隐切换 transaction.show(fragment01).hide(fragment02).hide(fragment03).hide(fragment04).commit(); //RadioGroup设置监听 rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) { switch (i){ case R.id.rb1: FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.show(fragment01).hide(fragment02).hide(fragment03).hide(fragment04).commit(); break; case R.id.rb2: FragmentTransaction transaction2 = getSupportFragmentManager().beginTransaction(); transaction2.show(fragment02).hide(fragment01).hide(fragment03).hide(fragment04).commit(); break; case R.id.rb3: FragmentTransaction transaction3 = getSupportFragmentManager().beginTransaction(); transaction3.show(fragment03).hide(fragment02).hide(fragment01).hide(fragment04).commit(); break; case R.id.rb4: FragmentTransaction transaction4 = getSupportFragmentManager().beginTransaction(); transaction4.show(fragment04).hide(fragment02).hide(fragment03).hide(fragment01).commit(); break; } } }); }}
阅读全文
0 0
- FrameLayout+底部按钮
- 使用Framelayout+linnerlayout实现按钮置于底部
- tablayout+底部底部按钮
- RadioGroup+FrameLayout实现底部导航页面
- FragmentTabHost+FrameLayout实现底部导航栏
- FragmentTabHost+FrameLayout实现底部导航栏
- FrameLayout加RadioGroup实现底部点击切换
- TabHost+TabWidget+FrameLayout实现底部菜单页面
- android-list底部按钮
- 底部按钮中间突出
- 底部切换按钮LuseenBottomNavigation
- popuwin 按钮底部
- 关于底部虚拟按钮
- 底部按钮RadioButton、RadioGroup
- RecycleView 底部按钮实现
- BottomTabBar底部按钮
- 侧拉+底部按钮
- Android 底部等分按钮
- Python每日小结(三)
- Heat 相关,Cloud-init & Cloud-config
- Int 拆装箱和缓存
- 移动端开发input标签调用数字键盘
- The partial sum problem
- FrameLayout+底部按钮
- IP-网际协议
- MongoDB 或者 redis 可以替代 memcached 吗?
- Kotlin 基础语法-03
- 淘宝双十一用哪些“潜规则”冲击1500亿?
- 解决前端跨域的正确姿势
- 程序猿节,自己写第一篇博客来纪念一下,记录一下自己的学习过程。
- 摘录兼容问题
- 自门控激活函数Swish