如何隐藏软键盘活动开始时, [英] How to hide Soft Keyboard when activity starts
问题描述
我有一个EditText与安卓windowSoftInputMode =stateVisible
的清单。现在,当我开始活动的键盘将被显示。如何隐藏的?我不能使用安卓windowSoftInputMode =stateHidden
,因为当键盘可见然后最小化应用程序,并恢复它的键盘应该是可见的。
我试着用
I have an Edittext with android:windowSoftInputMode="stateVisible"
in Manifest. Now the keyboard will be shown when I start the activity. How to hide it? I cannot use android:windowSoftInputMode="stateHidden
because when keyboard is visible then minimize the app and resume it the keyboard should be visible.
I tried with
InputMethodManager IMM =(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus()getWindowToken(),0)
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
但没有奏效。
推荐答案
使用下面的函数来显示/隐藏键盘:
Use the following functions to show/hide the keyboard:
/**
* 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);
}
这篇关于如何隐藏软键盘活动开始时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!