【发布时间】:2017-04-23 18:05:59
【问题描述】:
我正在尝试使用 RadioButtons 制作性别切换器。现在看起来像 this.
我使用矢量绘图作为图标。当按下按钮时,我想将其设为@color:colorAccent 并将其背景更改为白色圆圈。怎么做比较好?
layout.xml
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton"
android:background="?attr/selectableItemBackgroundBorderless"
android:layout_weight="1"
android:layout_marginEnd="8dp"
android:button="@drawable/custom_btn_radio"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton2"
android:background="?attr/selectableItemBackgroundBorderless"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:button="@drawable/custom_btn_radio"/>
</LinearLayout>
</RadioGroup>
custom_btn_radio.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/human_male"/>
<item android:state_checked="true"
android:drawable="@drawable/human_male"
android:background="@android:color/white"
android:tint="@color/colorAccent"/>
【问题讨论】:
标签: java android xml radio-button vector-graphics