Android的按钮选择和preSS绘制 [英] Android button select and press drawable
问题描述
我试图与国家preSS和选择按钮, 我已经做了相同的标签和它的作品,但我不知道为什么在这里是行不通的。 我已经做了这样的:
I'm trying to make a button with state press and select, I already did the same with tabs and it works but I don't know why here does not work. I have done it like this:
button_sel.xml
button_sel.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="@color/azulado"
android:endColor="@color/azulBrillante"
android:angle="270" />
<corners android:radius="@dimen/corner_radius" />
<stroke android:width="2px"
android:color="@color/blanco" />
</shape>
button_unsel.xml
button_unsel.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="@color/botonesD"
android:endColor="@color/botones"
android:angle="270" />
<corners android:radius="@dimen/corner_radius" />
<stroke android:width="2px"
android:color="@color/blanco" />
</shape>
和选择,button.xml:
And the selector, button.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_sel"
android:state_selected="true"
android:state_pressed="true"/>
<item android:drawable="@drawable/button_unsel"
android:state_selected="false"
android:state_pressed="false"/>
</selector>
在这里,我所说的绘制作为背景:
And here I call the drawable as a background:
<style name="button">
<item name="android:background">@drawable/button</item>
<item name="android:textSize">@dimen/text_size</item>
<item name="android:padding">@dimen/padding_button</item>
<item name="android:textColor">@color/blanco</item>
</style>
感谢您!!!!
推荐答案
在您选择的第一个项目仅用于,当按钮是pressed和选择。如果你想使用 button_sel
时,pressed或选定的按钮,你应该做的是这样的:
The first item in your selector is only used, when the button is pressed AND selected. If you want to use button_sel
when your button is pressed OR selected, you should do something like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_sel" android:state_selected="true" />
<item android:drawable="@drawable/button_sel" android:state_pressed="true" />
<item android:drawable="@drawable/button_unsel" />
</selector>
的项目进行评估,从上下,最后一个是默认的。虽然我不知道,如果state_selected是有道理的按钮。
The items are evaluated from top to bottom, the last one is the default. Though I am not sure if state_selected makes sense for buttons.
这篇关于Android的按钮选择和preSS绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!