zoukankan      html  css  js  c++  java
  • Android新手之旅(7) RadioButton的自定义

    希望用到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

  • 相关阅读:
    Golang flag包使用详解(一)
    string rune byte 的关系
    int在64位操作系统中占多少位?
    32位和64位系统区别及int字节数
    /etc/fstab修改及mkfs(e2label)相关应用与疑问
    nginx + fastcgi + c/c++
    MYSQL优化
    mysqlhighavailability
    woodmann--逆向工程
    jdaaaaaavid --github
  • 原文地址:https://www.cnblogs.com/jetz/p/2115223.html
Copyright © 2011-2022 走看看