我在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
但没有一个有任何好处。按钮在肯定后保持“按下”状态(意味着我消耗了触摸事件)setPressed
clearFocus
onTouch