0

我在CompoundDrawable按钮上定义 a 并对点击做出反应:

    mFileSelector.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        final int DRAWABLE_LEFT = 0;
        final int DRAWABLE_TOP = 1;
        final int DRAWABLE_RIGHT = 2;
        final int DRAWABLE_BOTTOM = 3;

        if (event.getAction() == MotionEvent.ACTION_UP) {
            if (event.getRawX() >= (mFileSelector.getRight() - mFileSelector.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                mFileSelector.setSelected(false);
                mFileSelector.setPressed(false);
                mFileSelector.clearFocus();
                return true;
            }
        }
        return false;
    }

如您所见,我已经尝试过,setSelected但没有一个有任何好处。按钮在肯定后保持“按下”状态(意味着我消耗了触摸事件)setPressedclearFocusonTouch

4

1 回答 1

0

你需要的是改变你的按钮的背景,这样的事情会帮助你。

 if (enabled) {
        your_button?.background = ContextCompat.getDrawable(this, R.drawable.round_button_blue)
    } else {
        your_button?.background = ContextCompat.getDrawable(this, R.drawable.round_button_gray)
    }
于 2019-01-14T22:07:06.697 回答