Android开发EditText不自动弹出键盘


带有EditText控件的在第一次显示的时候会自动获得focus,并弹出键盘,如果不想自动弹出键盘,有两种方法:

方法一:在mainfest文件中把对应的activity设置

android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。

方法二:可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。

注意TextView不要设置Visiable=gone,否则会失效

,可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus

注意TextView不要设置Visiable=gone,否则会失效

        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);


}


你可能感兴趣的:(android)