Android開發(fā)筆記之:如何屏蔽Button setClickable與setEnabled
更新時(shí)間:2013年05月28日 10:54:47 作者:
本篇文章是對(duì)在Android中,如何屏蔽Button setClickable與setEnabled的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
今天想讓按鍵暫時(shí)無效,滿足一定條件下才可以被用戶按到。最初以為是setClickable,誰知搞錯(cuò)了。
請(qǐng)看手冊(cè):
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
這個(gè)函數(shù)的意思是讓按鍵按一下。比如弄一個(gè)定時(shí)器,然后在手機(jī)上模擬,多長(zhǎng)時(shí)間到了讓按鍵自己按一下,而不是手動(dòng)去按,可以用這個(gè)函數(shù)。
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.
這個(gè)函數(shù)才是真正的,讓一個(gè)按鍵可以被用戶按,或者不可按。如果設(shè)為false,按鍵則會(huì)變成灰色的,按上去也沒反應(yīng)。當(dāng)設(shè)為true后,才會(huì)正常使用。這正是我找的函數(shù)。
請(qǐng)看手冊(cè):
復(fù)制代碼 代碼如下:
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
這個(gè)函數(shù)的意思是讓按鍵按一下。比如弄一個(gè)定時(shí)器,然后在手機(jī)上模擬,多長(zhǎng)時(shí)間到了讓按鍵自己按一下,而不是手動(dòng)去按,可以用這個(gè)函數(shù)。
復(fù)制代碼 代碼如下:
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.
這個(gè)函數(shù)才是真正的,讓一個(gè)按鍵可以被用戶按,或者不可按。如果設(shè)為false,按鍵則會(huì)變成灰色的,按上去也沒反應(yīng)。當(dāng)設(shè)為true后,才會(huì)正常使用。這正是我找的函數(shù)。
您可能感興趣的文章:
- Android控件系列之RadioButton與RadioGroup使用方法
- Android控件系列之Button以及Android監(jiān)聽器使用介紹
- Android定制RadioButton樣式三種實(shí)現(xiàn)方法
- Android自定義格式顯示Button的布局思路
- Android中button實(shí)現(xiàn)onclicklistener事件的兩種方式
- Android RadioButton單選框的使用方法
- Android控件之ToggleButton的使用方法
- Android 控件(button)對(duì)齊方法實(shí)現(xiàn)詳解
- Android點(diǎn)擊Button實(shí)現(xiàn)功能的幾種方法總結(jié)
- Android實(shí)現(xiàn)點(diǎn)擊Button產(chǎn)生水波紋效果
相關(guān)文章
Android中使用Theme來解決啟動(dòng)app時(shí)出現(xiàn)的空白屏問題
相信大多數(shù)人一開始都會(huì)對(duì)啟動(dòng)app的時(shí)候出現(xiàn)先白瓶或者黑屏然后才進(jìn)入第一個(gè)界面,例如:SplashActivity。那這是什么原因造成的呢?下面小編給大家介紹下2016-12-12
Android使用系統(tǒng)自帶的相機(jī)實(shí)現(xiàn)一鍵拍照功能
這篇文章主要介紹了Android使用系統(tǒng)自帶的相機(jī)實(shí)現(xiàn)一鍵拍照功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2017-01-01
AndroidStudio圖片壓縮工具ImgCompressPlugin使用實(shí)例
這篇文章主要為大家介紹了AndroidStudio圖片壓縮工具ImgCompressPlugin使用實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08
Android編程實(shí)現(xiàn)屏幕自適應(yīng)方向尺寸與分辨率的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)屏幕自適應(yīng)方向尺寸與分辨率的方法,涉及Android屏幕分辨率、布局、橫豎屏切換等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12
關(guān)于Android HTML5 audio autoplay無效問題的解決方案
這篇文章主要介紹了關(guān)于Android HTML5 audio autoplay無效問題的解決方案,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09
Android使用CircleImageView實(shí)現(xiàn)圓形頭像的方法
圓形頭像看起來非常美觀,下文通過實(shí)例代碼給大家介紹android中使用CircleImageView實(shí)現(xiàn)圓形頭像的方法,一起看看吧2016-09-09

