webview设置字体颜色、大小

改变 WebView上显示网页内容的CSS样式://字体颜色设为白色, “p”标签内的字体颜色“*”定义了字体大小以及行高;public final static String CSS_STYLE ="<style>* {font-size:16px;line-height:20px;}p {color:#FFFFFF;}</style>";//data是要显示的内容webView.loadDataWithBaseURL(null, CSS_STYLE+data, "text/html","utf-8", null);比较全的:public final static String CSS_STYLE ="<style>* {font-size:16px;line-height:20px;} p {color:#333;} a {color:#3E62A6;} img {max-width:310px;}pre {font-size:9pt;line-height:12pt;font-family:Courier New,Arial;border:1px solid #ddd;border-left:5px solid #6CE26C;background:#f6f6f6;padding:5px;}</style>";上面全局样式:“*”定义了字体大小以及行高;“p”标签内的字体颜色;“a”标签内的字体颜色;“img”标签的图片最大宽度;“pre”为代码样式;——————————————————————————————————————————————————借鉴自:其他:资讯内容是由服务返回的一串带HTML标签的字符串:String body = newsDetail.getBody();相关资讯则是由服务返回的数据组装的:String strRelative = "";for(Relative relative : newsDetail.getRelatives()){ strRelative += String.format("%s", relative.url, relative.title);}图片处理WebView上显示图片,不能直接显示大图,,这会影响页面的美观以及用户体验,因此要过滤掉原始图片的高宽属性,使用全局的图片样式。同时客户端可以根据用户设置,是否加载图片显示,以达到节省流量的目的。if(isLoadImage){ //过滤掉 img标签的width,height属性 body = body.replaceAll("(

]*?)\\s+width\\s*=\\s*\\S+","$1"); body = body.replaceAll("(

]*?)\\s+height\\s*=\\s*\\S+","$1");}else{ //过滤掉 img标签 body = body.replaceAll("<\\s*img\\s+([^>]*)\\s*>","");}WebView展示HTMLmWebView.loadDataWithBaseURL(null, body, "text/html", "utf-8",null);—————————————————————————————–其它方法:WebView webview= (WebView) findViewById(R.id.webview);WebSettings settings=webview.getSettings();settings.setTextSize(WebSettings.TextSize.SMALLEST);settings.setTextSize(WebSettings.TextSize.SMALLER);settings.setTextSize(WebSettings.TextSize.NORMAL);settings.setTextSize(WebSettings.TextSize.LARGER);settings.setTextSize(WebSettings.TextSize.LARGEST);

十七岁怎么会有七十岁的忧伤,十八岁怎么会有八十岁的等待。

webview设置字体颜色、大小

相关文章:

你感兴趣的文章:

标签云: