Android RadioButton 选中改变颜色

Android About 1,208 words

方法

新建文件,写在color文件夹下,不是 values 的 colors.xml,给RadioButtontextColor设置"@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(asvalues的是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>  
Views: 7,316 · Posted: 2019-04-11

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

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

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


Today On History
Browsing Refresh