我要在按钮上定义{
"id": "aa000aaa-a0a0-0000-a0aa-00000a000aa0",
"name": "Example Room",
"typeId": 14,
"parentSpaceId": "1b1b1111-b1b1-1111-111b-1b1b11b11111",
"subtypeId": 13,
"statusId": 12
}
并做出点击的反应:
CompoundDrawable
如您所见,我已经尝试过 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
为正(表示我消耗了触摸事件)之后,按钮保持在“按下”状态
答案 0 :(得分: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)
}