문제

나는 사용하려고 노력하고있다 ImageView A로 Button, 그리고 버튼을 누를 때마다 이미지를 변경할 수 있기를 원합니다. 나는있다 OnClickListener 설정하지만 사용자의 손가락이 더 이상 아래로 내려 가면 버튼 위로 어떻게해야합니까? 원본 이미지로 어떻게 되돌려고합니까?

도움이 되었습니까?

해결책

대신 사용자 :

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

이벤트 매개 변수는 그 경우를 알려줍니다 ACTION_DOWN 또는 ACTION_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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top