Android开发笔记之:如何屏蔽Button setClickable与setEnabled
更新时间:2013年05月28日 10:54:47 作者:
本篇文章是对在Android中,如何屏蔽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.
这个函数才是真正的,让一个按键可以被用户按,或者不可按。如果设为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后,才会正常使用。这正是我找的函数。
您可能感兴趣的文章:
相关文章
Android中使用Theme来解决启动app时出现的空白屏问题
相信大多数人一开始都会对启动app的时候出现先白瓶或者黑屏然后才进入第一个界面,例如:SplashActivity。那这是什么原因造成的呢?下面小编给大家介绍下2016-12-12
AndroidStudio图片压缩工具ImgCompressPlugin使用实例
这篇文章主要为大家介绍了AndroidStudio图片压缩工具ImgCompressPlugin使用实例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-08-08
关于Android HTML5 audio autoplay无效问题的解决方案
这篇文章主要介绍了关于Android HTML5 audio autoplay无效问题的解决方案,非常不错,具有参考借鉴价值,需要的朋友可以参考下2016-09-09
Android使用CircleImageView实现圆形头像的方法
圆形头像看起来非常美观,下文通过实例代码给大家介绍android中使用CircleImageView实现圆形头像的方法,一起看看吧2016-09-09


最新评论