选中时的Android单选按钮背景样式 [英] Android radiobutton background style when selected
本文介绍了选中时的Android单选按钮背景样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何为我的单选按钮设置背景.但我不知道更改所选单选按钮背景的最佳/正确方法是什么?是否可以在xml中制作或必须在代码中完成?
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?
问候
推荐答案
只需在drawable文件夹中创建一个选择器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屋!
查看全文