Android 禁止軟鍵盤自動彈出


Android系統對EditText這個控件有監聽功能,如果某個Activity中含有該控件,就會自動彈出軟鍵盤讓你輸入,這個看似人性化的方案有 時候並不被用戶喜歡的,所以在有些情況下要禁用該功能。這幾天做的應用也有這個問題,所以就查了,網上大部分都是如下方法:

<activity android:name=".MainActivity"
                android:screenOrientation="landscape"
                <span style="color:#ff0000;">android:windowSoftInputMode="adjustPan|stateHidden"
</span>                <span style="color:#ff0000;">android:configChanges="orientation|keyboardHidden</span>">         
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>       
     </activity> 

該方法確實有用,但只是在剛進入此Activity時能起到左右,如果該Activity中有Tab功能的切換,軟鍵盤又會彈出來,所以有了下面這個解決辦法:

在xml文件中加入一個隱藏的TextView:

<TextView
        android:id="@+id/config_hidden"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        />

然后再在Activity中加入:

TextView config_hidden = (TextView) this.findViewById(R.id.config_hidden);
config_hidden.requestFocus();

這樣軟鍵盤就不會彈出了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM