2009-08-07 7 views
1

私はをButtonとして使用しようとしています。ボタンを押すたびに画像を変更したいと思っています。私はOnClickListenerのセットを持っていますが、ユーザーの指がボタンの上になくなっても、何をする必要がありますか?元のイメージに戻すにはどうすればよいですか?代わりに、この画像ビューボタン用のAndroid onclickuplistener?

答えて

1

ユーザー:

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

イベントパラメータは、これを行うのそのACTION_DOWNまたはACTION_UP

3

正しい方法は、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>