RadioButton自定义样式 之一 换图片

来源:互联网 发布:网站用php与asp哪个好 编辑:程序博客网 时间:2024/06/06 01:45

radiobutton 、checkbox默认的图片太挫了,那我们自己来定义一下他的样式

1、找两张图片:选中和未选中的

2、再来张背景图片

3、定义状态

radiobutton_icon.xml

 

<?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/btn_check_off_selected" />  
    <item  
    android:state_checked="true"  
    android:drawable="@drawable/btn_check_on_selected" />  
</selector>

 

4、定义样式

 <style name="RadioBtnMyIcon"> 
    <item name="android:background">@drawable/item_bg</item> 
        <item name="android:button">@drawable/radiobutton_icon</item> 
</style> 

 

ok了,现在引用一下

 <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/RadioBtnMyIcon"
        android:text="选项1"
        />

效果 

 

select基础知识补充

<item> 

          android:state_pressed 
               Boolean“true”表示按下状态使用(例如按钮按下);“false” 
               表示非按下状态使用。 
           android:state_focused 

               Boolean“true”表示聚焦状态使用(例如使用滚动球/D-pad 
               聚焦Button);“false”表示非聚焦状态使用。 
           android:state_selected 

               Boolean“true”表示选中状态使用(例如Tab 打开);“false” 
               表示非选中状态使用。 
           android:state_checkable 

               Boolean“true”表示可勾选状态时使用;“false”表示非可 
               
勾选状态使用。(只对能切换可勾选非可勾选的构件有用。) 
           android:state_checked 

                 Boolean“true”表示勾选状态使用;“false”表示非勾选 
状态使用。 
           android:state_enabled 

               Boolean“true”表示可用状态使用(能接收触摸/点击事件); 
               “false”
表示不可用状态使用。 
           android:window_focused 

              Boolean“true”表示应用程序窗口有焦点时使用(应用程序 
              
在前台);“false”表示无焦点时使用(例如Notification栏拉 
              
下或对话框显示)。

     注意:记住一点,StateList中第一个匹配当前状态的item会被使用。因此,如果第一个item

     有任何状态特性的话,那么它将每次都被使用,这也是为什么默认的值必须总是在最后

 

 

 

 

 

 

0 0
原创粉丝点击