在图像按钮单击时Selector.xml不工作 [英] Selector.xml is not working when clicked on the image button
本文介绍了在图像按钮单击时Selector.xml不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的选择来改变图像按钮的图像,当我点击它。但是,这并不工作,大部分的时间。只为它工作几个按钮。不知道是什么这里的原因是
I use the following selector to change image of image button, when I click on it. But this does not work most of the times. Only for few buttons it works. Don't know what the cause here is
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>
但仍当我点击图像没有变化的。
but still image is not changing when I click.
任何猜测这个?
推荐答案
您在ImageButton的XML创建这样
you have create like this in the ImageButton xml
使用这样的按钮图像创建XML文件
create xml file using the button image like this
<?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
add that xml file as background for 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"/>
这篇关于在图像按钮单击时Selector.xml不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文