这一定是一个愚蠢的问题,因为在 stackoverflow 中有很多相关的问题,也许答案很简单。但无论如何,它就在这里。我有一个按钮并为它创建一个可绘制的 xml。所以在我的按钮下面是代码:
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="30dip"
android:background="@drawable/button2"
/>
现在在我的drawable/button2下我创建了一个我没有使用图像的选择器。这是我的代码:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#FF9E35" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="0dp"
android:topLeftRadius="8dp"
android:bottomLeftRadius="0dp"
android:topRightRadius="0dp"
android:bottomRightRadius="8dp" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#FF9E35"
android:endColor="#992f2f"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="0dp"
android:topLeftRadius="8dp"
android:bottomLeftRadius="0dp"
android:topRightRadius="0dp"
android:bottomRightRadius="8dp" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
</selector>
现在我要完成的是,当我单击该按钮时,它将其背景颜色更改为 state_pressed 所暗示的内容,并在单击另一个按钮时恢复正常(很可能是切换按钮)无论如何在代码上做在xml选择器后面还是在里面?
谢谢,
JC