当前位置:主页 > 移动开发 > Android代码 >

Android EditText默认不弹出输入法的实现方法

时间:2021-05-30 08:44:49 | 栏目:Android代码 | 点击:

一、Android EditText默认不弹出输入法的办法:

1. 在AndroidManifest.xml中将需要默认隐藏键盘的Activity中添加属性即可(常用此方法)

android:windowSoftInputMode="adjustUnspecified|stateHidden"
android:configChanges="orientation|keyboardHidden"

例如:

<activity
android:name=".activity.CheckInfoActivity"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustUnspecified|stateHidden"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"/>

2. 让 EditText失去焦点,使用EditText的clearFocus方法

EditText edit = (EditText)findViewById(R.id.edit);
edit.clearFocus();

3. 强制隐藏Android输入法窗口

EditText edit=(EditText)findViewById(R.id.edit);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(),0);

您可能感兴趣的文章:

相关文章