无法在 Nexus 7 选项卡中以编程方式隐藏默认软键盘
Not able to hide default soft keyboard programatically in Nexus 7 tab
我正在开发一个应用程序,我需要为文本打开我自己的自定义软键盘 input.To 为此,我将禁用默认软键盘并启用自定义软键盘。它在 Jelly Bean 版本上运行良好。但是,当我 运行 Nexus 7 Tab Kitkat 版本上的相同代码时,它不会隐藏默认的软键盘。我正在使用以下代码隐藏默认软件 Keyboard:Any 认为它不能在 Nexus 7 选项卡上使用 Kit Kat 版本??我研究了很多,但我一直无法弄清楚。
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
提前致谢
您可以尝试以下方法:
public void hideKeyboard(Activity context, View v) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
使用这个方法。
public static void hideKeyboard (Context context) {
try {
InputMethodManager inputManager = (InputMethodManager) context.getSystemService (Context.INPUT_METHOD_SERVICE);
View view = ((Activity) context).getCurrentFocus ();
if (view != null) {
inputManager.hideSoftInputFromWindow (view.getWindowToken (), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
catch (Exception e) {
e.printStackTrace ();
}
}
P.S。不要传递任何 view
。这将自动完成
我正在开发一个应用程序,我需要为文本打开我自己的自定义软键盘 input.To 为此,我将禁用默认软键盘并启用自定义软键盘。它在 Jelly Bean 版本上运行良好。但是,当我 运行 Nexus 7 Tab Kitkat 版本上的相同代码时,它不会隐藏默认的软键盘。我正在使用以下代码隐藏默认软件 Keyboard:Any 认为它不能在 Nexus 7 选项卡上使用 Kit Kat 版本??我研究了很多,但我一直无法弄清楚。
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
提前致谢
您可以尝试以下方法:
public void hideKeyboard(Activity context, View v) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
使用这个方法。
public static void hideKeyboard (Context context) {
try {
InputMethodManager inputManager = (InputMethodManager) context.getSystemService (Context.INPUT_METHOD_SERVICE);
View view = ((Activity) context).getCurrentFocus ();
if (view != null) {
inputManager.hideSoftInputFromWindow (view.getWindowToken (), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
catch (Exception e) {
e.printStackTrace ();
}
}
P.S。不要传递任何 view
。这将自动完成