RadioGroup实现点击的RadioButton项变色
16lz
2021-01-26
drawable下新建selector类型的文件<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@color/colorSelect"/>//选中时颜色 <item android:state_checked="false" android:drawable="@color/colorNoSelect"/>//未选中时颜色 <item android:drawable="@color/colorNoSelect"/>//默认颜色selector>//布局中RadioGroup代码,,,
在每个RadioButton中引用,刚才写的文件,android:background="@drawable/radio_selector"//给默认展示页面的对应的RadioButton中设置默认选中,android:cheched="true"
<RadioGroup android:id="@+id/radiogroup" android:orientation="horizontal" android:layout_width="match_parent" android:layout_alignParentBottom="true" android:layout_height="40dp"> <RadioButton android:id="@+id/home_button" android:background="@drawable/radio_selector" android:gravity="center" android:layout_width="0dp" android:button="@null" android:layout_weight="1" android:layout_height="match_parent" android:text="首页"/> <RadioButton android:id="@+id/zixuan_button" android:background="@drawable/radio_selector" android:gravity="center" android:layout_width="0dp" android:button="@null" android:layout_weight="1" android:layout_height="match_parent" android:text="自选"/> <RadioButton android:id="@+id/hangqing_button" android:background="@drawable/radio_selector" android:gravity="center" android:layout_width="0dp" android:button="@null" android:layout_weight="1" android:layout_height="match_parent" android:text="行情"/> <RadioButton android:id="@+id/zixun_button" android:background="@drawable/radio_selector" android:checked="true" android:gravity="center" android:layout_width="0dp" android:button="@null" android:layout_weight="1" android:layout_height="match_parent" android:text="资讯"/> <RadioButton android:id="@+id/jiaoyi" android:background="@drawable/radio_selector" android:gravity="center" android:layout_width="0dp" android:button="@null" android:layout_weight="1" android:layout_height="match_parent" android:text="交易"/>RadioGroup>
更多相关文章
- MT6573 android 2.3系统默认语言处理流程
- Android动画常用公共属性详解
- Android自定义ActionBar背景色、字体颜色等样式style
- Android(安卓)Studio 3.x.x降低compileSdkVersion的SDK版本
- TabLayout的使用及使用中的问题总结
- Android打开其它APP的两种方式
- Android(安卓)Studio使用小技巧:自定义Logcat
- Android:默认手机存储路径为TF卡
- android radioButton 动态设置背景