Android開發筆記之:如何屏蔽Button setClickable與setEnabled

來源:互聯網
上載者:User

今天想讓按鍵暫時無效,滿足一定條件下才可以被使用者按到。最初以為是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後,才會正常使用。這正是我找的函數。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.