文 | Promise Sun
1.場(chǎng)景描述:
1) APP項(xiàng)目中經(jīng)常會(huì)開發(fā)自定義軟鍵盤;同時(shí)在使用EditView時(shí)刻伊,也會(huì)常常遇到自動(dòng)彈出系統(tǒng)自帶的軟鍵盤证舟,與自定義的軟鍵盤產(chǎn)生沖突的情況拴曲;此時(shí)需要禁止EditView自動(dòng)彈出系統(tǒng)軟鍵盤误债,從而使自定義的軟鍵盤正常顯示浸船。
2) 正常的禁用系統(tǒng)軟鍵盤方法無(wú)法滿足需求,eg:在復(fù)制粘貼文本前寝蹈,選中EditView中的文本時(shí),Android系統(tǒng)會(huì)自動(dòng)調(diào)起軟鍵盤登淘,與自定義的軟鍵盤產(chǎn)生沖突箫老;此時(shí)需要特殊處理一下。
希望達(dá)到的效果是無(wú)論如何點(diǎn)擊EditView黔州,系統(tǒng)軟鍵盤絕對(duì)不會(huì)彈出來(lái)——實(shí)現(xiàn)徹底禁止EditView自動(dòng)彈出系統(tǒng)軟鍵盤耍鬓。
2. 功能實(shí)現(xiàn)
1)首先阔籽,在清單文件AndroidManifest.xml中,給EditView所在的Activity頁(yè)面設(shè)置屬性
android:windowSoftInputMode="stateHidden"
eg:(示例僅供參考)
<activity
android:name=".promise.sun.DemoActivity"
android:windowSoftInputMode="stateHidden"/>
2)然后牲蜀,找到EditView所在的xml布局文件笆制,找到EditView的父布局(容器),設(shè)置屬性
android:focusable="false"
android:focusableInTouchMode="false"
eg:(示例僅供參考)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/et_search"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_35"
android:layout_gravity="center"
android:background="@drawable/bg_white"
android:drawableLeft="@drawable/icon_search"
android:drawableRight="@drawable/icon_clear"
android:hint="請(qǐng)輸入"
android:maxLength="12"
android:maxLines="1"
android:paddingLeft="@dimen/dp_30"
android:paddingRight="@dimen/dp_10"
android:singleLine="true"
android:textColor="@color/app_black"
android:textColorHint="@color/grey_nine"
android:textColorHighlight="@color/blue_two"
android:textCursorDrawable="@drawable/cursor"
android:textSize="@dimen/sp_14" />
</RelativeLayout>
3)最后涣达,找到EditView所在的Activity在辆,在初始化時(shí)設(shè)置方法
editView.setShowSoftInputOnFocus(false);
4)完美解決,親測(cè)有效度苔。
版權(quán)聲明:本文為博主原創(chuàng)文章匆篓,轉(zhuǎn)載請(qǐng)點(diǎn)贊此文并注明出處,謝謝寇窑!