Android开发 屏蔽Button setClickable和setEnabled

今天想让按键暂时无效,满足一定条件下才可以被用户按到。最初以为是setClickable,谁知搞错了。

请看手册:

[java] 
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 
这个函数的意思是让按键按一下。比如弄一个定时器,然后在手机上模拟,多长时间到了让按键自己按一下,而不是手动去按,可以用这个函数。

 

 

 

[java] 
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 www.2cto.com
enabled True if the node is enabled. 
Throws 
IllegalStateException   If called from an AccessibilityService. 
这个函数才是真正的,让一个按键可以被用户按,或者不可按。如果设为false,按键则会变成灰色的,按上去也没反应。当设为true后,才会正常使用。这正是我找的函数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值