检测文本框,在Web视图中单击以弹出键盘

时间:2016-02-16 00:13:21

标签: android webview

如何在webview中检测文本框点击?我想在用户点击webview中的文本框时弹出键盘。我在我的代码中调用displayKeyboard()时会在代码中定义我的键盘会显示它但是如何触发该调用?

1 个答案:

答案 0 :(得分:1)

您可以这样做:

Button yourButton = new Button(context);
yourButton.setOnClickListener(this);

webView.addJavascriptInterface(yourButton,"injectedObject");

@Override
public void onClick(View v) {
    //displayKeyboard() 
}

HTML按钮将显示为:

<input type="submit" name="submit" id="some_id" onclick="yourButton.performClick();" />

您还可以阅读addJavascriptInterface

由于您没有对网页进行任何控制,您可能需要阅读以下内容:

HitTestResult

webview detuct html tag how android

请注意,你可能需要为此解密:

     int type = result.getType();

     if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) {
         return;
     }
相关问题