Android开发笔记之:如何屏蔽Button setClickable与setEnabled
程序员文章站
2023-11-16 17:55:52
今天想让按键暂时无效,满足一定条件下才可以被用户按到。最初以为是setclickable,谁知搞错了。请看手册:复制代码 代码如下:public void setclick...
今天想让按键暂时无效,满足一定条件下才可以被用户按到。最初以为是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.
这个函数才是真正的,让一个按键可以被用户按,或者不可按。如果设为false,按键则会变成灰色的,按上去也没反应。当设为true后,才会正常使用。这正是我找的函数。
请看手册:
复制代码 代码如下:
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.
这个函数才是真正的,让一个按键可以被用户按,或者不可按。如果设为false,按键则会变成灰色的,按上去也没反应。当设为true后,才会正常使用。这正是我找的函数。