帶有EditText控件的在第一次顯示的時候會自動獲得focus,並彈出鍵盤,如果不想自動彈出鍵盤,有兩種方法:
方法一:在mainfest文件中把對應的activity設置
android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。
方法二:可以在佈局中放一個隱藏的TextView,然後在onCreate的時候requsetFocus。
注意TextView不要設置Visiable=gone,否則會失效
,可以在佈局中放一個隱藏的TextView,然後在onCreate的時候requsetFocus。
注意TextView不要設置Visiable=gone,否則會失效
<TextView
android:id="@+id/text_notuse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
/>
TextView textView = (TextView)findViewById(R.id.text_notuse);
textView.requestFocus();
方法三:(本人測試,可用)
/**
*
* 隱藏軟鍵盤
*/
public static void hideSoftInputMode(Context context, View windowToken) {
InputMethodManager imm = ((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE));
imm.hideSoftInputFromWindow(windowToken.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}