1

私はこのボタンxmlを持っています。それが押されると、押された画像(b)は通常のボタンに戻る前に表示するのに長くなります。

ここに私のxmlがあります:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/a" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/b" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/b" />
<item android:drawable="@drawable/a" />

誰でもこれについて考えがありますか?

修正のために。私はこれを使いました。

closeButton.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(final View v, MotionEvent event) {
            switch(event.getAction())
            {
            case MotionEvent.ACTION_DOWN:
                v.setPressed(true);
                return true;
            case MotionEvent.ACTION_UP:
                v.setPressed(false);
                try {
            Thread.sleep(150);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        return true;
        }
            return false;  

        }
 });
4

2 に答える 2

1

このようにしてみてください..

Handler handler=new Handler();
mybutton.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.setPressed(true);
           handler.postDelayed(new Runnable() {
 @Override
 public void run() {
v.setPressed(false);
 }
 }, 2000);<-- you can set for how much time the button should be in pressed state..2 seco9nds in this case
            return true;
        }
    });
于 2012-03-30T05:05:26.367 に答える