Responsive website show on Web view out of mobile width(Not Responsive) other way in Chrome Looks Good

后端 未结 7 1813
抹茶落季
抹茶落季 2021-02-07 10:01

I am using webview to load the responsive website but it shows the width outside to the mobile size.

I open the link in a mobile Chrome browser and it looks

7条回答
  •  一向
    一向 (楼主)
    2021-02-07 10:27

    May be you can achieve with onPageFinished() method

    @Override
    public void onPageFinished(android.webkit.WebView view, String url)
    {
        super.onPageFinished(view, url);
    
        WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    
        DisplayMetrics metrics = new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(metrics);
    
        metrics.widthPixels /= metrics.density;
    
        wb.loadUrl("javascript:document.body.style.zoom = "+String.valueOf(scale)+";");
    
    OR//
        wb.loadUrl("javascript:var scale = " + metrics.widthPixels + " / document.body.scrollWidth; document.body.style.zoom = scale;");
    }
    

    it worked fine with me time ago. Hope this helps...

提交回复
热议问题