我试着用RadioButtons来改变性别。现在它看起来像这。
我使用矢量绘图作为图标。我想让它@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"/>发布于 2016-12-08 13:37:50
您应该使用为不同的状态选择不同的绘图。
然后,对于颜色,在使用向量绘图时,您可以对它的属性进行动画化:AnimVector,这样您就可以对颜色进行动画化,即使它是一个零持续时间的动画(理论上,这不是我做过的事情)。
https://stackoverflow.com/questions/41040461
复制相似问题