由网友(倾世年华、夜色未央)分享简介:我知道如何设置背景为我的单选按钮。但我不知道什么是最好的/正确的方式来改变单选按钮的背景是什么?是否有可能使其在XML或已在code做?I know how to set background for my radio button. But I don't know what is the best/right w...
我知道如何设置背景为我的单选按钮。但我不知道什么是最好的/正确的方式来改变单选按钮的背景是什么?是否有可能使其在XML或已在code做?
I know how to set background for my radio button. But I don't know what is the best/right way to change background of selected radio button? Is it possible to make it in xml or has to be done in code?
问候
推荐答案
刚刚创建的文件夹中绘制一个选择的xml文件
Just create a selector xml file in drawable folder
checkbox_background.xml
checkbox_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="@color/checkbox_active" />
<item android:state_checked="false" android:drawable="@color/checkbox_inactive" />
</selector>
和应用此背景下,以你的单选按钮
And apply this background to your radio buttons
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/checkbox_background" />
相关推荐
最新文章