当前位置:   article > 正文

Radiobutton的样式自定义_radiobuttonstyle

radiobuttonstyle

Radiobutton的样式自定义无非就是style,然后在radiobutton中引用。

自定义radiobutton

在style里面有相关属性:

background   来设置radiobutton的背景

button            来设置radiobutton的小框框,  当为null的时候,左边的按钮图片了

textcolor         来设置radiobutton的文字颜色

自定义的第一种style:  只修改radiobutton左边的按钮图片

 <style name="CustomRadioBtn">
        <item name="android:button">@drawable/mycustome_radio_selctor</item>
    </style>

mycustome_radio_selctor xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/enable_on_pressed" android:state_checked="true" android:state_enabled="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/enable_off_pressed" android:state_checked="false" android:state_enabled="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/enable_on" android:state_checked="true" android:state_enabled="true"/>
    <item android:drawable="@drawable/enable_off" android:state_checked="false" android:state_enabled="true"/>
    <item android:drawable="@drawable/disabled_on" android:state_checked="true" android:state_enabled="false"/>
    <item android:drawable="@drawable/disabled_off" android:state_checked="false" android:state_enabled="false"/>
</selector>

 第二种自定义样式style:  去除radiobutton左边的按钮图片,修改背景图

<style name="CustomRadioBtn2">
        <item name="android:gravity">center</item>
        <item name="android:background">@drawable/rb_nobtn_selector</item>
        <item name="android:button">@null</item>
    </style>

rb_nobtn_selector xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/rb_pressed_bg" android:state_checked="true"></item>
    <item android:drawable="@drawable/rb_normal_bg" android:state_checked="false"></item>
</selector>

 还可以自定义textcolor,一样的方法啦。

顺便提一下 Selector state状态对应说明:
android:drawable 放一个drawable资源
android:state_pressed 是否按下,如一个按钮触摸或者点击。
android:state_focused 是否取得焦点,比如用户选择了一个文本框。
android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
android:state_checked 被checked了,如:一个RadioButton可以被check了。

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/733639
推荐阅读
  

闽ICP备14008679号