视图中的EditText不显示键盘

时间:2014-08-11 19:55:20

标签: android android-softkeyboard

我的应用程序开始表现得很奇怪,所以我认为一定有一个我不理解的变化。我在RelativeLayout中有一个带有requestFocus属性的EditText。几个月后,我会打开我的应用并执行初始化方法,然后触摸编辑文本,键盘就会出现。现在键盘没有出现。我尝试使用InputMethodManager设置onClick Listener和onFocusChange:

m.showSoftInput(amountEditText, 0);

以及

m.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

由于这是一个新的,意外的行为,我担心我改变了一些导致这种奇怪行为的事情。我查看了视图的XML和WYSIWYG,看不出有什么问题。 SO答案似乎都有更复杂的情况,所以我认为更基本的东西是错误的。有人见过这个吗?

2 个答案:

答案 0 :(得分:1)

试试这个方法:

public static void showSoftkeyboard(android.view.View view, ResultReceiver resultReceiver) {
    Configuration config = view.getContext().getResources().getConfiguration();
    if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
        InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (resultReceiver != null) {
            imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT, resultReceiver);
        } else {
            imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
        }
    }
}

另外,如果您没有为您的活动禁用softKeyboard,请检查您的AndroidManifest.xml。

答案 1 :(得分:1)

前段时间我遇到了类似的问题。强制键盘显示的一种方法是这样:

    //here my EditText is called editText_search
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInputFromWindow(editText_search.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);

    editText_search.requestFocus();

另外,正如Simon Marquis指出的那样,看看你是否在你的Manifest中阻止或隐藏了键盘。

希望它有所帮助。