我尝试通过添加webview.requestFocus(View.FOCUS_DOWN);
和触摸监听器来解决此问题。它仅适用于第一次。当我导航到其他片段并返回到Webview时,单击输入字段时键盘未打开。不过,我仍然可以看到光标闪烁。我的Web视图是回收者视图的一部分,并放在其视图支架中。
wv_svg.setWebChromeClient(new WebChromeClient());
wv_svg.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
wv_svg.setFocusable(true);
wv_svg.setFocusableInTouchMode(true);
wv_svg.setClickable(true);
WebSettings settings = wv_svg.getSettings();
settings.setBuiltInZoomControls(true);
settings.setJavaScriptEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setSupportZoom(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setAppCacheEnabled(true);
settings.setDomStorageEnabled(true);
wv_svg.clearHistory();
wv_svg.addJavascriptInterface(new WebAppInterface(context), "Android");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
wv_svg.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
wv_svg.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
wv_svg.loadUrl(url);
wv_svg.requestFocus(View.FOCUS_DOWN);
wv_svg.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
v.requestFocus();
break;
}
return false;
}
});
答案 0 :(得分:0)
请将这些行添加到您的网络视图
android:focusable="true"
android:focusableInTouchMode="true"