我在清单中有一个带有android:windowSoftInputMode="stateVisible"
的编辑文本。现在,当我开始练习时,键盘将会显示出来。如何隐藏?我不能使用android:windowSoftInputMode="stateHidden
,因为当键盘可见时,最小化应用程序并恢复它,键盘应该是可见的。我试着用
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
但它并没有起作用。
发布于 2013-09-24 17:19:08
在AndroidManifest.xml
中
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="stateHidden" />
或者尝试
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
请同时查看this
发布于 2013-09-24 17:06:14
使用以下功能显示/隐藏键盘:
/**
* Hides the soft keyboard
*/
public void hideSoftKeyboard() {
if(getCurrentFocus()!=null) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}
/**
* Shows the soft keyboard
*/
public void showSoftKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
view.requestFocus();
inputMethodManager.showSoftInput(view, 0);
}
发布于 2016-04-19 14:48:18
只需向editText的父视图添加两个属性即可。
android:focusable="true"
android:focusableInTouchMode="true"
https://stackoverflow.com/questions/18977187
复制相似问题