Android系統對EditText這個控件有監聽功能,如果某個Activity中含有該控件,就會自動彈出軟鍵盤讓你輸入,這個看似人性化的方案有時候并不被使用者喜歡的,是以在有些情況下要禁用該功能。這幾天做的應用也有這個問題,是以就查了,網上大部分都是如下方法: [html] view plain copy
- <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:
[html] view plain copy
- <TextView
- android:id="@+id/config_hidden"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:focusable="true"
- android:focusableInTouchMode="true"
- />
然後再在Activity中加入:
[java] view plain copy
- TextView config_hidden = (TextView) this.findViewById(R.id.config_hidden);
[java] view plain copy
- config_hidden.requestFocus();
這樣軟鍵盤就不會彈出了。