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

  • 相关阅读:
    hiho_1139_二分+bfs搜索
    hiho_1138_island_travel
    google_apactest_round_A_problem_D
    hiho1122_二分图匈牙利算法
    hiho1123_好配对
    hiho1096_divided_product
    hiho1099_constellation
    hiho1093_spfa
    hiho1092_have lunch together
    【ipad神坑】ipad麦克风听不到声音怎么回事 微信QQ语音视频对方都听不到
  • 原文地址:https://www.cnblogs.com/jetz/p/2115223.html
Copyright © 2011-2022 走看看