Home > Web Front-end > HTML Tutorial > WebView使用总结(加载HTML内容形式的String)_html/css_WEB-ITnose

WebView使用总结(加载HTML内容形式的String)_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:07:25
Original
1142 people have browsed it

通过字符串拼凑的html页面显示: 
 

Java代码  

public void simpleJsClick() {  

        WebView webView = (WebView) findViewById(R.id.webview);  

        String html = ""  

                + "

"  

                + "图书封面
"  

                + "

"  

                + "

"  

                + "

"  

                + "

"  

                + "

"  

                + "

"  

                + "

"  

                + "

"  

                + "

" + "
WebView使用总结(加载HTML内容形式的String)_html/css_WEB-ITnose WebView使用总结(加载HTML内容形式的String)_html/css_WEB-ITnose
WebView使用总结(加载HTML内容形式的String)_html/css_WEB-ITnose WebView使用总结(加载HTML内容形式的String)_html/css_WEB-ITnose
" + "" + "";  

  

        webView.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);  

        webView.getSettings().setJavaScriptEnabled(true);  

        webView.setWebChromeClient(new WebChromeClient());  

    }  



7.在同种分辨率的情况下,屏幕密度不一样的情况下,自动适配页面: 

Java代码  

DisplayMetrics dm = getResources().getDisplayMetrics();  

   int scale = dm.densityDpi;  

   if (scale == 240) { //   

      webView.getSettings().setDefaultZoom(ZoomDensity.FAR);  

    } else if (scale == 160) {  

      webView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);  

    } else {  

      webView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);  

}  



8.判断加载的页面URL地址是否正确: 

Java代码  

if(URLUtil.isNetworkUrl(url)==true)  



9.设置WebView的一些缩放功能点: 

Java代码  

webView.getSettings().setJavaScriptEnabled(true);  

webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);  

webView.setHorizontalScrollBarEnabled(false);  

webView.getSettings().setSupportZoom(true);  

webView.getSettings().setBuiltInZoomControls(true);  

webView.setInitialScale(70);  

webView.setHorizontalScrollbarOverlay(true);  


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template