[英]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.