【问题标题】:Keypad hide/show in webview键盘在 web 视图中隐藏/显示
【发布时间】:2014-03-08 20:01:48
【问题描述】:

我已经试过了。它适用于三星平板电脑。

在第 1_4.html 页上,我必须隐藏键盘,在 2.html 上,我必须显示 键盘。

在文本框上都单击 webview 内

注意:Android Activity 相同。

我在 webView.setOnTouchListener 上调用此代码

        if (value.equals("1") || value.equals("4")) {
            
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
            
        } else if(value.equals("2")) {
            getWindow().clearFlags( WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        }

但它不适用于任何手机。它给了我警告

W/InputMethodManager(25060): startInputInner : InputBindResult == null

我已经谷歌了。但是没有发现任何有用的东西。

我现在该怎么办?任何帮助将不胜感激。

【问题讨论】:

    标签: android webview android-keypad android-input-method


    【解决方案1】:

    试试这个代码:这适用于所有设备。

     try
     {
        if(isopen)
        {    
           // to hide keyboard
           InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService(Activity.INPUT_METHOD_SERVICE);
           inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
        }else{
           // to open keyboard
           InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
           inputMethodManager.toggleSoftInputFromWindow(linearLayout.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
        }
        }
        catch (NullPointerException e) 
        {
        }
        catch (Exception e) 
        {
        }
    

    【讨论】:

    • 显示键盘怎么样?我已经编辑了我的问题。请看。
    • 要强行打开键盘吗?
    • 无论如何,我只想在 2.html 页面和 other 页面上显示 键盘 b> 我想隐藏它。
    • 不工作!在平板电脑中,它会隐藏几毫秒,然后再次出现。而且在电话里它根本没有隐藏!
    【解决方案2】:

    要打开键盘试试这个

    webview.postDelayed(new Runnable() {
               @Override
               public void run() {
                   InputMethodManager keyboard = (InputMethodManager)
                   MainActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
                   keyboard.showSoftInput(webview, 0);
               }
    },100); 
    

    要关闭键盘试试这个

    InputMethodManager inputMethodManager = (InputMethodManager)MainActivity.this.getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(), 0);
    

    【讨论】:

    • 它应该在任何文本框点击 webview 内!它会起作用吗?
    • postDelayed 是关键。谢谢!
    猜你喜欢
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 2019-07-23
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多