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自定義view實(shí)現(xiàn)電影票在線選座功能
這篇文章主要為大家詳細(xì)介紹了Android自定義view實(shí)現(xiàn)選座功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11Android 設(shè)置應(yīng)用全屏的兩種解決方法
本篇文章小編為大家介紹,Android 設(shè)置應(yīng)用全屏的兩種解決方法。需要的朋友參考下2013-04-04Android8.0適配前臺(tái)定位服務(wù)service的示例代碼
這篇文章主要介紹了Android8.0適配前臺(tái)定位服務(wù)service的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07Android 開發(fā)使用PopupWindow實(shí)現(xiàn)加載等待界面功能示例
這篇文章主要介紹了Android 開發(fā)使用PopupWindow實(shí)現(xiàn)加載等待界面功能,結(jié)合實(shí)例形式分析了Android使用PopupWindow組件實(shí)現(xiàn)加載等待界面功能相關(guān)布局與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下2020-05-05FrameLayout和Fragment處理Android應(yīng)用UI布局實(shí)例
這篇文章主要介紹了FrameLayout和Fragment處理Android應(yīng)用UI布局實(shí)例,安卓3.0以后Fragment的出現(xiàn)為多尺寸屏幕的適配帶來了方便,需要的朋友可以參考下2016-02-02Android實(shí)現(xiàn)九宮格抽獎(jiǎng)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)九宮格抽獎(jiǎng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06Android 進(jìn)度條顯示在標(biāo)題欄的實(shí)現(xiàn)方法
android進(jìn)度條顯示在標(biāo)題欄的實(shí)現(xiàn)方法,大概分文xml文件和java文件,具體代碼內(nèi)容大家可以通過本文學(xué)習(xí)下2017-01-01