我正在尝试使用状态按下和选择来制作一个按钮,我已经对选项卡做了同样的事情并且它可以工作,但我不知道为什么这里不起作用。我已经这样做了:
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
<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:
<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>
在这里,我将可绘制对象称为背景:
<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>
谢谢!!!!