setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN)设置失败

webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);这个属性可以让webview只显示一列,也就是自适应页面大小 不能左右滑动,但在使用中发现,只针对4.4以下有效,因为4.4的webview内核改了,Google也在api中说了,要么改html样式,要么改变WebView;


@SuppressLint("NewApi")
	private void openWebView(String urlDate) {
	    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
	    	tvRouterDesc.getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
	    } else {
	    	tvRouterDesc.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
	    }
	    tvRouterDesc.loadDataWithBaseURL(null, getHtmlData(urlDate), "text/html", "utf-8", null);
	    tvRouterDesc.getSettings().setJavaScriptEnabled(false); 
	}

	private String getHtmlData(String bodyHTML) {
	    String head = "<head><style>img{max-width: 100%; width:auto; height: auto;}</style></head>";
	    return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
	}



你可能感兴趣的:(setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN)设置失败)