Android Webview图片未加载

时间:2015-05-24 13:56:46

标签: android android-webview

我使用WebView创建了一个简单的应用。但有些图像并没有加载。

正确(在我的电脑中):

enter image description here

错误(在模拟器中):

enter image description here

正确:

enter image description here

错误:没有横幅

enter image description here

所以我使用Chrome调试进行了调试,发现我的代码已更改。

enter image description here

我不会添加noscriptstyle="display:none;visibility:hidden;"

谁知道如何解决这个问题?

代码在这里

public class MainActivity extends Activity {

private WebView webView;
private ProgressBar mPBar;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    webView = (WebView) findViewById(R.id.webView1);
    mPBar = (ProgressBar) findViewById(R.id.progress01);
    WebSettings set = webView.getSettings();

    set.setJavaScriptEnabled(true);
    set.setCacheMode(WebSettings.LOAD_DEFAULT);
    webView.loadUrl("http://something.kr"); // 보여주고자 하는 주소

    //set.setCacheMode(WebSettings.LOAD_NO_CACHE);
    set.setSupportZoom(false);
    Log.i("DEBUG", set.getUserAgentString());

    webView.setWebViewClient(new WebClient());



    webView.setWebChromeClient(new WebChromeClient()
    {
        public void onProgressChanged(WebView view, int progress) {
            if (progress<100)
            {
                mPBar.setVisibility(ProgressBar.VISIBLE);
            }
            else if (progress==100)
            {
                mPBar.setVisibility(ProgressBar.GONE);
            }
            mPBar.setProgress(progress);
        }




    });}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
    if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
        if(webView.canGoBack()){
            webView.goBack();
        }else{
            webView.clearCache(false);
            finish();
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);

}

private class WebClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if (url.startsWith("sms:")) {
            Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse(url));
            startActivity(i);
            return true;
        }

        if (url.startsWith("kakaolink:")) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(i);
            return true;
        }


        if(url.startsWith("tel")){
            Intent i = new Intent(Intent.ACTION_DIAL);
            i.setData(android.net.Uri.parse(url));
            startActivity(i);

        } else {
            view.loadUrl(url);

        }



        return true;




    }}
}

1 个答案:

答案 0 :(得分:4)

来自Android文档:

  

Android 5.0会更改您应用的默认行为。如果你的应用程序   目标API级别21或更高:系统阻止混合内容和   第三方cookie默认情况下......    - https://developer.android.com/about/versions/android-5.0-changes.html

所以试试这个:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);