android radiogroup样式(设置切换背景与文字颜色)

2018-11-28 09:55:53

RadioButton(单选按钮)在Android开发中应用的非常广泛,比如一些选择项的时候,会用到单选按钮。它是一种单选框双状态的按钮,可以选择或不选择。在RadioButton没有被选中时,用户能够按下或点击来选中它。

RadioGroup和RadioButton的关系:

1、RadioButton表示单个圆形单选框,而RadioGroup是可以容纳多个RadioButton的容器

2、每个RadioGroup中的RadioButton同时只能有一个被选中

3、不同的RadioGroup中的RadioButton互不相干,即如果组A中有一个选中了,组B中依然可以有一个被选中

4、大部分场合下,一个RadioGroup中至少有2个RadioButton

5、大部分场合下,一个RadioGroup中的RadioButton默认会有一个被选中,并建议您将它放在RadioGroup中的起

始位置

注: RadioGroup继承至LinearLayout,所以LinearLayout的属性RadioGroup都可以使用。

RadioButton特殊属性:

  • android:drawable 设置图片可以选着图片位置

  • android:checked   控件是否选中

  • android:button     隐藏圆圈

注:button基本属性就不做细讲


 main.xml

<RadioGroup
                android:id="@+id/radioGroup1"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:orientation="horizontal" >

                <RadioButton
                    android:id="@+id/radio0"
                    android:layout_width="0dp"//设0才可以与radio1平分宽度
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/radio_check"
                    android:button="@null"
                    android:checked="true"
                    android:gravity="center"
                    android:text="@string/title"
                    android:textColor="@drawable/radio_text_check" />

                <RadioButton
                    android:id="@+id/radio1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/radio_check"
                    android:button="@null"
                    android:gravity="center"
                    android:text="@string/title2"
                    android:textColor="@drawable/radio_text_check" />

            </RadioGroup>

 

radio_text_check.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:color="@android:color/white"/>
    <item android:state_checked="false" android:color="@android:color/holo_blue_bright"/>

</selector>

 

radio_check.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/image1" android:state_checked="true"/>
    <item android:drawable="@drawable/image2" android:state_checked="false"/>

</selector>
  • 2020-05-24 08:10:18

    echarts标题(title)配置

    show:true,//显示策略,默认值true,可选为:true(显示) | false(隐藏) text: '主标题',//主标题文本,'\n'指定换行 link:'',//主标题文本超链接,默认值true target: null,//指定窗口打开主标题超链接,支持'self' | 'blank',不指定等同为'blank'(新窗口) subtext: '副标题',//副标题文本,'\n'指定换行 sublink: '',//副标题文本超链接

  • 2020-06-02 08:57:12

    clipboard复制成功但是粘贴板是空的

    将文本复制到剪贴板应该不难。配置它不需要几十个步骤,也不需要加载数百KB的js文件 。但最重要的是,它不应该依赖Flash或任何臃肿的框架。这就是clipboard.js存在的原因。

  • 2020-06-04 13:54:21

    vue生成的__ob__: Observer无法解析jsonp

    computed 从vuex获得数据,watch监听数据 然而问题就出现在了监听上,监听不到,给个setTimeOut 1000 就能检测到数据了,不然打印时又数据,用的时候时空的,不知道时什么原因。

  • 2020-06-06 20:22:56

    laravel 接收json串

    在做项目的时候发现 用平时的$request->all() 无法获取到请求值