Android RadioButton选中改变颜色

AndroidRadioButton大约 1201 字

新建文件,写在color文件夹下,不是values的colors.xml,给RadioButton的textColor设置"@color/xxx"。

  • radiobutton字体颜色改变color_radiobutton.xml
<?xml version="1.0" encoding="utf-8"?>  
<selector xmlns:android="http://schemas.android.com/apk/res/android">  
      <item android:state_checked="true" android:color="@color/color_text_selected"/>    
      <!-- not selected -->    
      <item android:state_checked="false" android:color="@color/color_text_normal"/>    
</selector>  
  • radiobutton背景颜色改变radio_group_selector.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="@color/color_bg_selected"/>
    <item android:state_checked="false" android:drawable="@color/color_bg_normal"/>
</selector>  
  • color.xml(as的values的是colors.xml文件)
<color name="transparent">#000000</color>  
<color name="color_bg_selected">#e0301e</color>  
<color name="color_bg_normal">#e7e7e8</color>  
<color name="color_text_selected">#ffffff</color>  
<color name="color_text_normal">#000000</color>  
阅读 1506 · 发布于 2019-04-11

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看换一批