Android底部导航栏点击切换变色
2018-02-06 10:33
477 查看
底部导航栏切换是由RadioGroup中的RadioButton点击事件切换的,其实之前的文章中已经介绍了,但是在这里详细说明一下。
1.1 底部导航栏的布局文件bottom_bar.xml如下:
每个RadioButton的drawableTop表示文字上面的图片,我们在drawable文件下分别建home_drawable.xml,dashboard_drawable.xml和notification_drawable.xml文件。其中home_drawable.xml文件如下:
表示RadioButton不同状态图片的颜色变化。其他两个文件内容也是一样,这样就能实现点击RadioButton改变
颜色,不需要再代码中显示的改变颜色。
1.1 底部导航栏的布局文件bottom_bar.xml如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/bottom_bar" android:paddingTop="0dp" android:paddingBottom="0dp" android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/bottom_bar_background" android:gravity="center_horizontal" android:orientation="horizontal" android:tint="@color/qmui_config_color_gray_4"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="@color/qmui_config_color_10_pure_black" /> <RadioGroup android:id="@+id/main_radiogroup" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal"> <RadioButton android:id="@+id/main_rab_house" android:checked="true" android:text="主页" style="@style/main_rbt" android:drawableTop="@drawable/home_drawable"/> <RadioButton android:id="@+id/main_rab_connect" style="@style/main_rbt" android:text="连接" android:drawableTop="@drawable/dashboard_drawable" /> <RadioButton android:id="@+id/main_rab_wifi" style="@style/main_rbt" android:text="配置" android:drawableTop="@drawable/notification_drawable"/> </RadioGroup> </LinearLayout> </LinearLayout>
每个RadioButton的drawableTop表示文字上面的图片,我们在drawable文件下分别建home_drawable.xml,dashboard_drawable.xml和notification_drawable.xml文件。其中home_drawable.xml文件如下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_checked="true" android:drawable="@drawable/ic_home_gray_24dp" ></item> <item android:state_checked="false" android:drawable="@drawable/ic_home_blue_24dp"></item> </selector>
表示RadioButton不同状态图片的颜色变化。其他两个文件内容也是一样,这样就能实现点击RadioButton改变
颜色,不需要再代码中显示的改变颜色。
相关文章推荐
- 安卓底部导航栏点击变色切换不同Fragment
- Android开发之TabLayout真正实现底部导航栏(可实现点击文字颜色图片切换)
- Android实现简单底部导航栏 Android仿微信滑动切换效果
- Android点击水纹效果和QQ拖拽效果的底部导航栏
- android app主题UI界面框架搭建 tablayout+Viewpager+fragment 导航栏滑动和点击切换界面
- Android之新闻客服端顶部导航栏Tab点击和左右滑动实现切换界面
- 移动端底部菜单点击切换图标变色
- Android例子—Fragment实例讲解—底部导航栏+ViewPager滑动切换页面
- Android项目ViewPager+Fragment+RadioButton实现底部导航栏切换
- android 点击底部图片进行切换不同的Fragment
- Android之新闻客服端顶部导航栏Tab点击和左右滑动实现切换界面
- android仿美团底部导航栏的点击效果——揭露动画
- Android ViewPager实现滑动切换页面+底部tab点击切换页面(类微信首页)
- Android TabLayout、ViewPager实现顶部和底部Tab导航 点击滑动切换Tab页面
- Android——Fragment实例精讲——底部导航栏+ViewPager滑动切换页面
- Android基础入门教程——5.2.4 Fragment实例精讲——底部导航栏+ViewPager滑动切换页面
- android 可滑动、点击切换的导航栏
- mui底部导航栏点击切换图片和颜色
- Android中Tab的应用,底部,随选择切换图标和文字颜色
- Android仿相册点击屏幕出现标题和底部菜单