我这样称呼这个方法:
getInputMethodManager().showSoftInput(view, 0, resultReceiver);但是,我的屏幕上没有显示键盘,resultReceiver也没有收到onReceiveResult(int resultCode, Bundle resultData)中的消息。视图不是null和hasFocus() == true。
有人知道这个问题吗?非常感谢。
谢谢Karthik和Imen。我需要知道这个方法不起作用的根本原因,而不是一些解决办法。
更新2017/10/23
我在android源代码中进行了调试,发现:一个名为mServedView的变量为null,该方法将返回一个false。但是,official doc没有说明为什么或者何时这个方法会返回一个false。
发布于 2017-10-20 11:16:39
就像这样:
用于显示键盘:
public void showSoftKeyboard(Context ctx, View v) {
InputMethodManager imm = (InputMethodManager) ctx.getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}用于隐藏键盘:
public void hideSoftKeyboard(Context ctx, View v) {
InputMethodManager inputManager = (InputMethodManager) ctx.getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}发布于 2017-10-20 11:45:35
试试这个方法:
public void showSoftKeyboard(View aView) {
if (aView != null) {
aView.setFocusable(true);
aView.setFocusableInTouchMode(true);
aView.requestFocus();
InputMethodManager keyboard = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(aView, 0);
}
}https://stackoverflow.com/questions/46847592
复制相似问题