preface
As a complete App, Annon lacks webView-related content. However, in some cases, such as only displaying privacy policy, loading H5 pages through WebView will cause more overhead and lack user experience. H5 takes about 200ms to complete loading, and according to the native loading data, there is almost no pause in the loading process (based on the network speed). The tool is still a work in progress and will gradually enrich its functionality as it goes along.
Introduction to the
Native display H5 page, with set styles.
rendering
It’s a simple pure display.
Method of use
HtmlTextUtils.showJustText(tvHtml, source);
Copy the code
TextView tvHtml: Target control.
String source: Source data.
The source code in this
package com.momin.baselib.util;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;
/** * <p>Title: HtmlTextUtils</p> * <p>Description: TextView Copyright: </p> </p> * *@author Momin
* @version 1.0
* @date2020/11/18 11:03 * /
public class HtmlTextUtils {
/** * displays only text content **@paramTextView target control *@paramSource Destination source */
public static void showJustText(TextView textView, String source) {
if (textView == null) {
return;
}
// Overflow scroll
textView.setMovementMethod(ScrollingMovementMethod.getInstance());
CharSequence charSequence;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
charSequence = Html.fromHtml(source,Html.FROM_HTML_MODE_LEGACY);
} else{ charSequence = Html.fromHtml(source); } textView.setText(charSequence); }}Copy the code