如何屏蔽Button setClickable与setEnabled
今天想让按键暂时无效,满足一定条件下才可以被用户按到。最初以为是setClickable,谁知搞错了。
请看手册:
public void setClickable (boolean clickable)
Since: API Level 14
Sets whether this node is clickable.
Note: Cannot be called from an AccessibilityService. This class is made immutable before being delivered to an AccessibilityService.
Parameters
clickable True if the node is clickable.
Throws
IllegalStateException If called from an AccessibilityService.
public void setContentDescription (CharSequence contentDescr
这个函数的意思是让按键按一下。比如弄一个定时器,然后在手机上模拟,多长时间到了让按键自己按一下,而不是手动去按,可以用这个函数。
public void setEnabled (boolean enabled)
Since: API Level 14
Sets whether this node is enabled.
Note: Cannot be called from an AccessibilityService. This class is made immutable before being delivered to an AccessibilityService.
Parameters
enabled True if the node is enabled.
Throws
IllegalStateException If called from an AccessibilityService.
android setClickable 一定要放在 按扭的setOnClickListener事件之后!
因为setOnClickListener事件会去重写View v,也就是会把setClickable设为TRUE!
所以一定要写成:
GetFinger = (Button)findViewById(R.id.GetFinger);
GetFinger.setBackgroundColor(100);
GetFinger.setOnClickListener(this);
//设置两按扭为不可点击
GetFinger.setClickable(false);