//设置WebView启用js web.getSettings().setJavaScriptEnabled(true); //关闭自动适应 web.getSettings().setUseWideViewPort(false); web.getSettings().setLoadWithOverviewMode(false); //重写WebViewClient中的onPageFinished方法 web.setWebViewClient(new WebViewClient(){ @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); //修改图片大小 int screenWidth = ScreenUtil.getScreenWidth(getActivity()); String width = String.valueOf(DensityUtils.dp2px(getActivity(),50)); String width2=String.valueOf(DensityUtils.px2dp(getActivity(),screenWidth)-40); String javascript = "javascript:function ResizeImages() {" + "var myimg,oldwidth;" + "var maxwidth = document.body.clientWidth;" + "for(i=0;i <document.images.length;i++){" + "myimg = document.images[i];" + "if(myimg.width > "+width2+"){" + "oldwidth = myimg.width;" + "myimg.width ="+width2+";" + "}" + "}" + "}"; view.loadUrl(javascript); view.loadUrl("javascript:ResizeImages();"); } });
安卓WebView加载Html标签时,显示变小或者不能适应屏幕宽度的问题
最新推荐文章于 2024-06-15 11:15:55 发布