UI界面
這個沒有什麼,寫個webview控件就ok
<WebView
android:id="@+id/web_introduction"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Java代碼
getHtmlData() 爲富文本全屏適配的方法
String tv_html = coursePageBean.getResult().getLessontext();//這裏寫從後臺獲取富文本字符串
StringBuilder sb = new StringBuilder();
sb.append(getHtmlData(tv_html));
web_introduction.loadDataWithBaseURL(null,sb.toString(),"text/html", "utf-8", null);
getHtmlData()方法
/**
* 富文本適配
*/
private String getHtmlData(String bodyHTML) {
String head = "<head>"
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> "
+ "<style>img{max-width: 100%; width:auto; height:auto;}</style>"
+ "</head>";
return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
}
OK,Android WebView加載富文本並全屏適配齊活,歡迎評論指點,共同學習,共勉