【问题标题】:Open softkeyboard when webview input text gets focus当 webview 输入文本获得焦点时打开软键盘
【发布时间】:2023-04-03 13:21:01
【问题描述】:

我有一个基于 webview 的应用程序,当我将焦点放在某些输入上时,我希望在其中打开相应的键盘。使用我在下面提供的代码,它会打开,但即使对于数字类型输入,它也总是会打开 qwerty 键盘。

private void ShowKeyboard(final boolean show) {
    try {
        runOnUiThread(new Runnable() {
             @Override
             public void run() {
                 if (show) {
                      InputMethodManager mgr = (InputMethodManager) General.MainShellReference.getSystemService(Context.INPUT_METHOD_SERVICE);
                      mgr.showSoftInput(General.appView, InputMethodManager.SHOW_IMPLICIT);
                      ((InputMethodManager) General.MainShellReference.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(General.appView, 0);
                    } else {
                        getWindow().setSoftInputMode(
                                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                    }
            }
        });

    } catch (Exception ex) {
        ;
    }
}

【问题讨论】:

    标签: android android-webview android-softkeyboard android-keypad


    【解决方案1】:

    我想你已经尝试过使用<input type="number" /><input type="tel" />。无论如何尝试这样做。

    你看到了吗:Is there a way to have a masked numeric input field? http://blog.pamelafox.org/2012/05/triggering-numeric-keyboards-with-html5.html

    【讨论】:

    • 感谢您的回复,但我的问题是我的键盘被强行打开并打开了 qwerty。如果我点击文本字段,它将打开正确的字段,但在强制打开时不会打开
    猜你喜欢
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 2014-11-03
    • 2021-07-20
    相关资源
    最近更新 更多