zoukankan      html  css  js  c++  java
  • 如何屏蔽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);

  • 相关阅读:
    PHP获取今天、昨天、明天的日期
    PHP使用Apache中的ab测试网站的压力性能
    php 数组操作
    ajax实时获取下拉数据
    php微信支付测试开发(流程已通)
    微信支付调用JSAPI缺少参数:timeStamp
    JS dom最常用API
    Javascript刷新页面的几种方法
    php+mysql 安全
    隐式的类类型转换
  • 原文地址:https://www.cnblogs.com/exmyth/p/5104525.html
Copyright © 2011-2022 走看看