Android取消EditText自動(dòng)獲取焦點(diǎn)默認(rèn)行為
更新時(shí)間:2012年12月25日 09:39:25 作者:
在項(xiàng)目中,一進(jìn)入一個(gè)頁(yè)面, EditText默認(rèn)就會(huì)自動(dòng)獲取焦點(diǎn),很是郁悶,Android 如何讓EditText不自動(dòng)獲取焦點(diǎn)?于是搜集整理一番,曬出來(lái)和大家分享,希望對(duì)你們有所幫助
在項(xiàng)目中,一進(jìn)入一個(gè)頁(yè)面, EditText默認(rèn)就會(huì)自動(dòng)獲取焦點(diǎn)。
那么如何取消這個(gè)默認(rèn)行為呢?
在網(wǎng)上找了好久,有點(diǎn) 監(jiān)聽(tīng)軟鍵盤(pán)事件,有點(diǎn) 調(diào)用 clearFouse()方法,但是測(cè)試了都沒(méi)有! xml中也找不到相應(yīng)的屬性可以關(guān)閉這個(gè)默認(rèn)行為
解決之道:在EditText的父級(jí)控件中找一個(gè),設(shè)置成
android:focusable="true"
android:focusableInTouchMode="true"
這樣,就把EditText默認(rèn)的行為截?cái)嗔耍?
<LinearLayout
style="@style/FillWrapWidgetStyle"
android:orientation="vertical"
android:background="@color/black"
android:gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
>
<ImageView
android:id="@+id/logo"
style="@style/WrapContentWidgetStyle"
android:background="@drawable/dream_dictionary_logo"
/>
<RelativeLayout
style="@style/FillWrapWidgetStyle"
android:background="@drawable/searchbar_bg"
android:gravity="center_vertical"
>
<EditText
android:id="@+id/searchEditText"
style="@style/WrapContentWidgetStyle"
android:background="@null"
android:hint="Search"
android:layout_marginLeft="40dp"
android:singleLine="true"
/>
</RelativeLayout>
</LinearLayout>
那么如何取消這個(gè)默認(rèn)行為呢?
在網(wǎng)上找了好久,有點(diǎn) 監(jiān)聽(tīng)軟鍵盤(pán)事件,有點(diǎn) 調(diào)用 clearFouse()方法,但是測(cè)試了都沒(méi)有! xml中也找不到相應(yīng)的屬性可以關(guān)閉這個(gè)默認(rèn)行為
解決之道:在EditText的父級(jí)控件中找一個(gè),設(shè)置成
復(fù)制代碼 代碼如下:
android:focusable="true"
android:focusableInTouchMode="true"
這樣,就把EditText默認(rèn)的行為截?cái)嗔耍?
復(fù)制代碼 代碼如下:
<LinearLayout
style="@style/FillWrapWidgetStyle"
android:orientation="vertical"
android:background="@color/black"
android:gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
>
<ImageView
android:id="@+id/logo"
style="@style/WrapContentWidgetStyle"
android:background="@drawable/dream_dictionary_logo"
/>
<RelativeLayout
style="@style/FillWrapWidgetStyle"
android:background="@drawable/searchbar_bg"
android:gravity="center_vertical"
>
<EditText
android:id="@+id/searchEditText"
style="@style/WrapContentWidgetStyle"
android:background="@null"
android:hint="Search"
android:layout_marginLeft="40dp"
android:singleLine="true"
/>
</RelativeLayout>
</LinearLayout>
您可能感興趣的文章:
- Android控件系列之EditText使用方法
- android同時(shí)控制EditText輸入字符個(gè)數(shù)和禁止特殊字符輸入的方法
- Android中EditText實(shí)現(xiàn)不可編輯解決辦法
- Android定制自己的EditText輕松改變底線顏色
- Android編程設(shè)置TextView顏色setTextColor用法實(shí)例
- Android更改EditText下劃線顏色樣式的方法
- Android 設(shè)置Edittext獲取焦點(diǎn)并彈出軟鍵盤(pán)
- 全面解析Android中對(duì)EditText輸入實(shí)現(xiàn)監(jiān)聽(tīng)的方法
- android基礎(chǔ)教程之a(chǎn)ndroid的listview與edittext沖突解決方法
- Android中EditText setText方法的踩坑實(shí)戰(zhàn)
相關(guān)文章
Android使用Retrofit實(shí)現(xiàn)自定義Converter解析接口流程詳解
Retrofit是一個(gè)RESTful的HTTP網(wǎng)絡(luò)請(qǐng)求框架的封裝,網(wǎng)絡(luò)請(qǐng)求的工作本質(zhì)上是OkHttp完成,而Retrofit僅負(fù)責(zé)網(wǎng)絡(luò)請(qǐng)求接口的封裝2023-03-03Android TextView的TextWatcher使用案例詳解
這篇文章主要介紹了Android TextView的TextWatcher使用案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08Android自定義View實(shí)現(xiàn)圓形加載進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)圓形加載進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06Android側(cè)滑菜單和輪播圖之滑動(dòng)沖突問(wèn)題
這篇文章主要介紹了Android側(cè)滑菜單和輪播圖之滑動(dòng)沖突問(wèn)題,需要的朋友可以參考下2017-06-06Android?Studio調(diào)試Gradle插件詳情
這篇文章主要介紹了Android?Studio調(diào)試Gradle插件詳情,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容戒殺,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09Android 自定義標(biāo)題欄的實(shí)例詳解
這篇文章主要介紹了 Android 自定義標(biāo)題欄的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家實(shí)現(xiàn)這樣類(lèi)似的功能,需要的朋友可以參考下2017-10-10Android數(shù)據(jù)庫(kù)中事務(wù)操作方法之銀行轉(zhuǎn)賬示例
這篇文章主要介紹了Android數(shù)據(jù)庫(kù)中事務(wù)操作方法之銀行轉(zhuǎn)賬,以具體的銀行轉(zhuǎn)賬為例分析了Android數(shù)據(jù)庫(kù)操作中事務(wù)的使用與回滾相關(guān)操作技巧,需要的朋友可以參考下2017-08-08