更新时间:2023-10-13 19:44:58
是的,有一种方法可以根据需要更改背景,但是您必须使用像这样的选择器作为背景:
Yes, there is a way to change the background as you wish, but you have to use a selector like this as background:
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/some_image" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/some_other_image" />
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/some_image1" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/other_image" />
</selector>
For @Drawable, etc. (you can use a color or make a gradient. Check this for more information about gradients.