当选择Android的单选按钮背景样式 [英] Android radiobutton background style when selected
本文介绍了当选择Android的单选按钮背景样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何设置背景为我的单选按钮。但我不知道什么是最好的/正确的方式来改变单选按钮的背景是什么?是否有可能使其在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" />
这篇关于当选择Android的单选按钮背景样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文