的WebView必须装载两次,以正确加载 [英] WebView must be loaded twice to load correctly

查看:159
本文介绍了的WebView必须装载两次,以正确加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在与第一web视图加载网页,有时图像丢失或显示不正确。如果我重新加载页面web视图总是显示完美。我知道,大家首先会想到我设置Javascript使用loadURL后,但事实并非如此。

When the page with the WebView first loads, sometimes images are missing or displayed incorrectly. If I reload the page the WebView always displays perfectly. I know everyone will first think I set javascript after loadUrl, but that isn't true.

在我的onCreate有:

In onCreate I have:

learnWebView = (WebView)findViewById(R.id.learnWebView);
learnWebView.setWebViewClient(new WebViewClient());
learnWebView.getSettings().setJavaScriptEnabled(true);

然后在后面的onCreate后调用该函数我有:

Then later in the function called after onCreate I have:

learnWebView.loadUrl("myurl");

是的,我知道,与使用loadURL该功能后的onCreate每次调用。

And yes, I know that the function with loadUrl is called after onCreate every time.

推荐答案

我没有在 WebViewClient shouldOverrideUrlLoading code>

I haven't seen this issue since overriding shouldOverrideUrlLoading in WebViewClient

learnWebView.getSettings().setJavaScriptEnabled(true);
learnWebView.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }
});

虽然我不确定为什么这会有所作为,因为返回false只是应该让你的的WebView 处理所有URL的开口。

Although I'm uncertain as to why this would make a difference, because returning false is just supposed to make your WebView handle all url openings.

这篇关于的WebView必须装载两次,以正确加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆