用于显示简单HTML的TextView
本项目已停止维护。4.0 是最后一个发布版本。
欢迎 fork 本项目并接手维护。
HtmlTextView 是 Android 的一个扩展 TextView 组件,它可以通过将非常简单的 HTML 转换为 Android Spannable 对象来显示内容。
除了支持一小部分 HTML 标签外,该库还允许从本地 drawables 文件夹或互联网加载图片。
该库保持小巧,无外部依赖。
将以下内容添加到你的 build.gradle 中:
repositories {
jcenter()
}
dependencies {
compile 'org.sufficientlysecure:html-textview:4.0'
}<org.sufficientlysecure.htmltextview.HtmlTextView
android:id="@+id/html_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="@android:style/TextAppearance.Small" />HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text);
// loads html from string and displays cat_pic.png from the app's drawable folder
htmlTextView.setHtml("<h2>Hello wold</h2><ul><li>cats</li><li>dogs</li></ul>",
new HtmlResImageGetter(htmlTextView));或
HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text);
// loads html from string and displays cat_pic.png from the app's assets folder
htmlTextView.setHtml("<h2>Hello wold</h2><ul><li>cats</li><li>dogs</li></ul>",
new HtmlAssetsImageGetter(htmlTextView));或
HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text);
// loads html from string and displays http://www.example.com/cat_pic.png from the Internet
htmlTextView.setHtml("<h2>Hello wold</h2>",
new HtmlHttpImageGetter(htmlTextView));或
HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text);
// loads html from raw resource, i.e., a html file in res/raw/,
// this allows translatable resource (e.g., res/raw-de/ for german)
htmlTextView.setHtml(R.raw.help, new HtmlHttpImageGetter(htmlTextView));或
<TextView
android:id="@+id/html_text"
android:layout_暂无开放 Issues,或尚未同步最近议题。