当我单击它时,我使用以下选择器更改图像按钮的图像。但这在大多数时候不起作用。仅适用于几个按钮。不知道这里是什么原因
mapselector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Button Pressed -->
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/mapiconover"/>
</selector>
在按钮中,
我正在这样做,
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/btnMap" android:layout_centerInParent="true" android:src="@drawable/mapselector"
android:background="@drawable/map" android:scaleType="fitXY"
android:layout_alignParentBottom="true">
</ImageButton>
但是当我点击时静止图像没有改变。
对此有什么猜测吗?
最佳答案
你已经在 ImageButton xml 中这样创建了
像这样使用按钮图像创建 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/backbutton" />
<item
android:drawable="@drawable/closebutton" />
</selector>
将该 xml 文件添加为 IMageButton 的背景
<ImageButton
android:layout_height="50px"
android:layout_width="50px"
android:id="@+id/settings"
android:background="@drawable/settings_button" //setting_button in
the xml file
android:text="Settings"/>
关于android - 单击图像按钮时 Selector.xml 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7884791/