简体   繁体   English

如何在Webview中请求焦点到特定文本字段?

[英]How can I request focus to specfic text field in webview?

I want to open keyboard immediately after opening my app. 我想在打开应用程序后立即打开键盘。 For example If I load google.com in webview then search field should be tapped automatically and keyboard should be shown. 例如,如果我在Webview中加载google.com,则应该自动点击搜索字段并显示键盘。

My code: 我的代码:

   webView.loadUrl("http://google.com");

When user opens the activity, directly field of search should be selected and keyboard should be visible instead of him tapping manually on that. 当用户打开活动时,应直接选择搜索字段,并且键盘应该可见,而不是他手动点击该字段。 Is there a way? 有办法吗?

Try add this: 尝试添加以下内容:

webView.getSettings().setJavaScriptEnabled(true);

webView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        view.loadUrl("javascript:document.getElementsByName('q')[0].focus();");
        super.onPageFinished(view, url);
    }
});

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何移植 OEM 特定应用程序? - How can I port OEM specfic app? 我怎样才能给这个密码字段焦点? - How can I give this password field focus? 如何在退出应用程序之前使文本字段失去焦点? - How can I make a text field lose focus before application quits? 如何在POST请求中提交一个文本字段,将blob上传到Blobstore并在blob的上传处理程序中检索它? - How can I submit a text field in the POST request that uploads a blob to the Blobstore and retrieve it in the upload handler for the blob? 如何验证文本字段上是否存在光标/焦点 - How to verify cursor/focus is present on a text field 如何更改 Android 中 webview 中文本的颜色? - How can I change the color of the text in webview in Android? 如何调整Swing文本字段的大小? - How can I resize a Swing text field? 将焦点设置到文本字段 - Setting the focus to a text field 如何限制arraylist在泛型之前只接受特定类型的对象 - How can I restrict the arraylist to accept only a specfic type of object prior to generic 我需要以编程方式在WebView内打开的网页中填充文本字段。 如何? - I need to fill text field programatically in a web page opened inside a WebView. How To?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM