[英]Phone screen turns white after clicking back from Android Webview
I am using Android Webview to load some web content into my app. 我正在使用Android Webview将一些Web内容加载到我的应用中。 The loading page has some Javascript content, so I have to set the ' webSettings.setJavaScriptEnabled(true)" as true, the problem is when i click back from the webpage whole phone screen turns to white blank screen.
加载页面包含一些Javascript内容,因此我必须将'webSettings.setJavaScriptEnabled(true)“设置为true,问题是当我从网页上单击返回时,整个电话屏幕变成了白色的空白屏幕。
I found one more thing is if i set webSettings.setJavaScriptEnabled(false) the webview loads the page successfully, but not fully shows the content as expected. 我发现还有另一件事是,如果我将webSettings.setJavaScriptEnabled(false)设置为webview,则会成功加载页面,但未按预期完全显示内容。 I am using the Code below.
我正在使用下面的代码。 How can i get rid of this issue ?
我如何摆脱这个问题? Searched so many places and couldn't find any helpful answer.
搜索了很多地方,找不到任何有用的答案。
private void initView() {
initWebView();
initWebSettings();
}
@SuppressLint("NewApi")
private void initWebView() {
setWebChromeClient(new WebChromeClientCustom());
setWebViewClient(new WebViewClientCustom());
setOnLongClickListener(this);
setFocusableInTouchMode(true);
requestFocus();
}
@SuppressLint("SetJavaScriptEnabled")
private void initWebSettings() {
final WebSettings webSettings = getSettings();
webSettings.setUseWideViewPort(false);
webSettings.setLoadWithOverviewMode(false);
webSettings.setSupportMultipleWindows(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
webSettings.setAppCacheEnabled(true);
}
If you want to close Activity that holds WebView when back pressed, you can override onBackPressed
method and close the activity: 如果要关闭回按下时保存WebView的Activity,可以重写
onBackPressed
方法并关闭该活动:
@Override
public void onBackPressed() {
finish();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.