在使用Radiobutton中的小技巧(RadioButton的背景选择器,)
2018-02-25 23:46
302 查看
在使用radiobutton中的技巧问题
因为radiobutton一般在作为导航栏使用时,几个radioButton的格式相同,文本内容和图片有区别,其他的格式保持一致
顾故可以在编写代码时将 相同的总结在一起
如下面的例子:
1.1主页面MainActivity的布局
这部分代码直接在values 下的==》styles中
拿出一个为例 @drawable/iv_main_drawable_selector其他几个选择器写法一样,需要图片的下载源码找图片吧,这里就不一一写出了
因为radiobutton一般在作为导航栏使用时,几个radioButton的格式相同,文本内容和图片有区别,其他的格式保持一致
顾故可以在编写代码时将 相同的总结在一起
如下面的例子:
1.1主页面MainActivity的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout android:id="@+id/fl_main" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" /> <RadioGroup android:id="@+id/rg_main" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="0" android:background="#dbdbdb" android:orientation="horizontal"> <RadioButton android:id="@+id/rb_main" style="@style/RadioButton_Style" android:drawableTop="@drawable/iv_main_drawable_selector" android:text="首页" /> <RadioButton android:id="@+id/rb_video" style="@style/RadioButton_Style" android:drawableTop="@drawable/iv_video_drawable_selector" android:text="视频" /> <RadioButton android:id="@+id/rb_care_about" style="@style/RadioButton_Style" android:drawableTop="@drawable/iv_care_about_drawable_selector" android:text="关心" /> <RadioButton android:id="@+id/rb_person" style="@style/RadioButton_Style" android:drawableTop="@drawable/iv_person_drawable_selector" android:text="我的" /> </RadioGroup> </LinearLayout>1.2 Style公共部分提取: // style="@style/RadioButton_Style"
这部分代码直接在values 下的==》styles中
<!--RadioButton相同的部分提取--> <style name="RadioButton_Style"> <!-- 提取RadioButton中公共部分 --> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:button">@null</item> <item name="android:textColor">@drawable/tv_main_text_color_selector</item> <item name="android:layout_weight">1</item> <item name="android:gravity">center</item> <item name="android:drawablePadding">3dp</item> <item name="android:padding">3dp</item> <item name="android:textSize">10sp</item> </style>1.3 RadioButton字体颜色选择器: //@drawable/tv_main_text_color_selector
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
//首先是未选中的颜色 <item android:state_checked="false" android:color="#7A7A7A"></item>
//选中的颜色 <item android:state_checked="true" android:color="#F85959"></item> </selector>1.4 RadioButton图片选择器:
拿出一个为例 @drawable/iv_main_drawable_selector其他几个选择器写法一样,需要图片的下载源码找图片吧,这里就不一一写出了
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
//未选中的图片 <item android:state_checked="false" android:drawable="@drawable/iv_main"></item>
//选中按钮后的图片 <item android:state_checked="true" android:drawable="@drawable/iv_main_press"></item> </selector>
相关文章推荐
- Android Button的四种点击事件及RadioButton 的点击事件,背景选择器<selector>的使用
- WinForm的RadioButton使用小技巧
- Android——selector背景选择器的使用详解(二)
- [水晶报表小技巧-使用-1]隔行背景换色
- android背景选择器selector使用方法
- Android的selector背景选择器使用
- 使用radioGroup的时候,每个radioButton的状态选择器要使用 state_checked=""属性,不能使用selected
- android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现
- android selector 背景选择器的使用
- android的selector,背景选择器的使用
- 更改Calendar背景图(使用系统映像选择器)
- day day up--Android背景选择器selector的使用
- Android selector背景选择器的使用详解
- android背景选择器selector使用方法
- android背景选择器selector使用方法
- 更改Calendar的背景图片(使用系统图片选择器)
- android资源文件的使用(背景选择器,动画等)
- android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现
- Android selector背景选择器的使用详解
- android背景选择器selector使用方法