android onclickuplistener用于imageview按钮?

android onclickuplistener用于imageview按钮?,android,button,onclick,android-widget,Android,Button,Onclick,Android Widget,我正在尝试将图像视图用作按钮,我希望能够在按下按钮时更改图像。我设置了一个OnClickListener,但是当用户的手指不再向下时,我该怎么办呢?如何还原到原始图像?请改为使用此用户: View.OnTouchListener abstract boolean onTouch(View v, MotionEvent event) 事件参数将让您知道它的操作是否向下或操作是否向上用户: View.OnTouchListener abstract boolean onTouch(View v,

我正在尝试将
图像视图
用作
按钮
,我希望能够在按下按钮时更改图像。我设置了一个
OnClickListener
,但是当用户的手指不再向下时,我该怎么办呢?如何还原到原始图像?

请改为使用此用户:

View.OnTouchListener
abstract boolean onTouch(View v, MotionEvent event)
事件参数将让您知道它的
操作是否向下
操作是否向上

用户:

View.OnTouchListener
abstract boolean onTouch(View v, MotionEvent event)

事件参数将让您知道它的
ACTION\u DOWN
ACTION\u UP
正确的方法是扩展按钮类,或者如果您只想更改按钮图像,则可以通过xml设置样式

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/btn_default_normal_disable" />
    <item android:state_pressed="true" 
        android:drawable="@drawable/btn_default_pressed" />
    <item android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/btn_default_selected" />
    <item android:state_enabled="true"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_focused="true"
        android:drawable="@drawable/btn_default_normal_disable_focused" />
    <item
         android:drawable="@drawable/btn_default_normal_disable" />
</selector>

    
    

正确的方法是扩展按钮类,或者如果您只想更改按钮图像,可以通过xml设置样式

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/btn_default_normal_disable" />
    <item android:state_pressed="true" 
        android:drawable="@drawable/btn_default_pressed" />
    <item android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/btn_default_selected" />
    <item android:state_enabled="true"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_focused="true"
        android:drawable="@drawable/btn_default_normal_disable_focused" />
    <item
         android:drawable="@drawable/btn_default_normal_disable" />
</selector>