现在的位置: 首页 > 综合 > 正文

Android新手之旅(7) RadioButton的自定义

2011年05月23日 ⁄ 综合 ⁄ 共 1765字 ⁄ 字号 评论关闭

希望用到RadioGroup的功能,但遇到一些看似简单问题却无法解决:系统的图标太大却难以更换,在网上找解决方案。有些地方提到,由于用的是图片,所以无法缩小,只好自定义,参考1 参考2

然后,找图标,在sdk文件夹下搜索含radio的文件,很多,选一套合适的即可。

这是在res/drawable下的radiobutton.xml文件

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
          android:state_enabled="true"
          android:state_checked="true"
          android:drawable="@drawable/check" />
    <item             
          android:state_enabled="true"    
          android:state_checked="false"
          android:drawable="@drawable/checknull" />
</selector>

这是radiogroup的定义。注意:

1、RadioGroup 方向是水平,android:orientation="horizontal" 。

2、button的样式是android:button = "@drawable/radiobutton"。为了找这个属性费了大劲了。

<RadioGroup android:id="@+id/radioGroup1" android:paddingTop="30px" android:paddingLeft="15px" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" >
    <RadioButton android:text="今天" android:layout_width="wrap_content" android:textSize="14px" android:checked="true" android:layout_height="wrap_content" android:editable="false" android:id="@+id/radio0"  android:button = "@drawable/radiobutton" android:paddingLeft="30px" android:layout_marginRight="2px" android:textColor="#000"></RadioButton>
    <RadioButton android:text="昨天" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radio1" android:textSize="14px" android:button = "@drawable/radiobutton" android:paddingLeft="30px" android:layout_marginRight="2px" android:textColor="#000"></RadioButton>
    <RadioButton android:text="前天" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radio2" android:textSize="14px"  android:button = "@drawable/radiobutton" android:paddingLeft="30px" android:layout_marginRight="2px" android:textColor="#000"></RadioButton>
</RadioGroup>

image

抱歉!评论已关闭.