WebView 不加载图像 [英] WebView not load images

查看:35
本文介绍了WebView 不加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Android WebView 上上传我的网站,除了加载我网站上的一些图片外,一切正常.

<代码>Form->create('A');if($evento['Evento']['habilitar_asientos']){?><div id="mapa_tickets" style="width:100%;height:350px;margin-bottom:15px;"><svg width="100%" height="100%"><?if($evento['Evento']['imagen_recinto']){?><image xlink:href="<?echo $evento['Evento']['imagen_recinto'];?>"x="0" y="0" height="100%" width="100%" class="base"/><?}foreach ($ticketsActivos 作为 $ticket) {if($ticket['Ticket']['imagen_recinto']){?><image xlink:href="<?echo $ticket['Ticket']['imagen_recinto'];?>"x="0" y="0" height="100%" width="100%"class="<?echo $ticket['Ticket']['id'];?>"/><?}}?></svg>

因此,我正在为我的 webview 充电.

protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);WebView myWebView = (WebView) this.findViewById(R.id.webView1);myWebView.getSettings().setJavaScriptEnabled(true);WebSettings s = myWebView.getSettings();if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){s.setAllowUniversalAccessFromFileURLs(true);s.setAllowFileAccessFromFileURLs(true);}myWebView.loadUrl("http://mysite.cl/eventos/evento-completo/inscripciones/seleccion_tickets/");}

此外,在我所携带的网站内,没有让您继续购买的按钮,但是每次我单击一个按钮时,它都会告诉我打开浏览器,并且流程不遵循 webview 中的流程.

解决方案

尝试添加这行代码,

webView.getSettings().setLoadsImagesAutomatically(true);

您也可以设置这些属性..

 webView.getSettings().setLoadsImagesAutomatically(true);webView.getSettings().setJavaScriptEnabled(true);webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);webView.getSettings().setBuiltInZoomControls(true);

试试下面的代码,粘贴...

 webView.setWebViewClient(new MyWebView());webView.setWebChromeClient(new WebChromeClient() {public void onProgressChanged(WebView view, int progress){progressBar.setProgress(progress);如果(进度== 100)progressBar.invalidate();}});

和这是一个内部类...

私有类 MyWebView 扩展了 WebViewClient {@覆盖public boolean shouldOverrideUrlLoading(WebView view, String url) {view.loadUrl(url);返回真;}@覆盖公共无效 onLoadResource(WebView 视图,字符串 url){super.onLoadResource(view, url);progressBar.setProgress(view.getProgress());}@覆盖public void onPageFinished(WebView view, String url) {super.onPageFinished(view, url);progressBar.invalidate();}}

我希望您已将权限添加为

 <uses-permission android:name="android.permission.INTERNET"/>

I'm trying to upload my site on an Android WebView, everything works fine except load some pictures that I have on my site.

<?
echo $this->Form->create('A');
if($evento['Evento']['habilitar_asientos']){?>
<div id="mapa_tickets" style="width:100%;height:350px;margin-bottom:15px;">
<svg width="100%" height="100%">

<?
if($evento['Evento']['imagen_recinto']){?>
    <image xlink:href="<?echo $evento['Evento']['imagen_recinto'];?>" x="0" y="0" height="100%" width="100%" class="base"/>
<?}
foreach ($ticketsActivos as $ticket) {
    if($ticket['Ticket']['imagen_recinto']){?>
        <image xlink:href="<?echo $ticket['Ticket']['imagen_recinto'];?>" x="0" y="0" height="100%" width="100%"class="<?echo $ticket['Ticket']['id'];?>"/>
    <?}
}
?>
</svg>
</div>

Thus, I am charging my webview.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView myWebView = (WebView) this.findViewById(R.id.webView1);
    myWebView.getSettings().setJavaScriptEnabled(true);
    WebSettings s = myWebView.getSettings();
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
        s.setAllowUniversalAccessFromFileURLs(true);
        s.setAllowFileAccessFromFileURLs(true);
    }
    myWebView.loadUrl("http://mysite.cl/eventos/evento-completo/inscripciones/seleccion_tickets/");
}

In addition, within the site that I am carrying no to pushing buttons that let you keep buying here, but every time I click on a button, it tells me to open the browser and the flow does not follow within the webview.

解决方案

Try adding this line of code,

webView.getSettings().setLoadsImagesAutomatically(true);

You can also set these properties..

        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webView.getSettings().setBuiltInZoomControls(true);

Give a try to the below code, just paste...

        webView.setWebViewClient(new MyWebView());

        webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                progressBar.setProgress(progress);
                if(progress == 100)
                    progressBar.invalidate();
            }
        });

and this as an inner class...

private class MyWebView extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onLoadResource(WebView view, String url) {
        super.onLoadResource(view, url);
        progressBar.setProgress(view.getProgress());
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        progressBar.invalidate();
    }
}

and i hope you have added the permission as

 <uses-permission android:name="android.permission.INTERNET" />

这篇关于WebView 不加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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