質問

私はImageViewとしてButtonを使用しようとしている、と私は、ボタンの押されたときにイメージを変えることができるようにしたいです。私はOnClickListenerが設定されているが、私はボタンの上に、ユーザの指がダウンしなくなったときについて何をすべきかを持っているのですか?どのように私は、元の画像に戻りますか?

役に立ちましたか?

解決

ユーザーの代わりにこの:

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

イベントパラメータは、あなたが知っているようになるならば、そのACTION_DOWNまたはACTION_UP

他のヒント

これを行うための正しい方法は、Buttonクラスを拡張するか、あなただけのボタン画像を変更したい場合は、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