如何创建一个单选按钮切换特定状态抽拉XML [英] How to create a state-specific drawable xml for a toggle RadioButton
问题描述
在创建按钮可绘制,我通常遵循以下格式来实现背景的onclick事件的变化:
When creating button drawables, I typically follow the following format to implement an "onClick" change of background:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/RESOURCE_FOR_CLICKED" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/RESOURCE_FOR_CLICKED" />
<item android:drawable="@drawable/RESOURCE_NORMAL" />
</selector>
这对我来说工作得很好,当我创建传统的按钮,因为我希望他们能够恢复到原来的状态,一旦的onClick
完成,并且我没有实施任何code。
This works fine for me when I am creating traditional buttons as I want them to return to their original state once onClick
is finished, and I don't have to implement any code.
然而,这不适用于单选
工作,因为我其实是想一旦他们选择了他们的背景绘制是在非$ P $不同pssed状态。
However, this does not work for RadioButton
s because I actually want their background drawable to be different in the non-pressed state once they have selected.
对于涉及单选按钮的状态,我应该知道的实施这样的事情有XML属性?如果不是这样,我必须管理code背景的变化?
Are there XML attributes for states involving radio buttons that I should be aware of to implement this sort of thing? If not, do I have to manage the changing of backgrounds in code?
推荐答案
的android:state_checked
将让您指定当选择无线电项目的绘制
android:state_checked
will let you specify a drawable for when a radio item is selected.
这篇关于如何创建一个单选按钮切换特定状态抽拉XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!