Button保持pressed状态

button = (Button) this.findViewById(R.id.button);
button.setTag(false);
button.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP)
            if ((boolean) v.getTag()) {
                v.setPressed(false);
                v.setTag(false);
                return false;
            } else {
                v.setPressed(true);
                v.setTag(true);
                return true;
            }
        return false;
    }});

来自于:
http://stackoverflow.com/a/31712303/4349466

你可能感兴趣的:(Button保持pressed状态)