XML-android中的OnTouch更改图像

XML-android中的OnTouch更改图像,xml,imageview,selector,Xml,Imageview,Selector,我在drawable文件夹中有一个xml文件,我想用作ImageView src。代码如下: <?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/home2" />

我在drawable文件夹中有一个xml文件,我想用作ImageView src。代码如下:

<?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/home2" />
<item android:state_pressed="false" android:drawable="@drawable/home1"></item>
</selector>

正如你所见,我希望每次按下图像时,它都会将图像更改为另一个图像,但由于某些原因,它无法正常工作。它只显示默认图像,当我按下图像时,它不会被切换

此外,我尝试输入此代码,但得到了相同的结果:

<?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/home2" />
<item android:drawable="@drawable/home1"></item>
</selector>


解决方案是什么?

您的意思是,例如,在按下image=home1之前,当按下image=home2时,以及当用户释放pressing image=home2时,它不会再次更改。 如果是这样,您可以使用此代码

<item android:state_pressed="true"
    android:drawable="@drawable/home2" />