HTML Builder
Build valid HTML for Android TextView.
Description
There is a lovely method on the android.text.Html class, fromHtml(), that converts HTML into a Spannable for use with a TextView.
However, the documentation does not stipulate what HTML tags are supported, which makes this method a bit hit-or-miss. This small library provides a fluent API for building valid HTML for android.widget.TextView.
Usage
HtmlBuilder html = new HtmlBuilder();
html.p("Lorem ipsum dolor sit amet, denique detraxit reprimique quo in. Ius dicat omnes mucius cu.");
html.font().color("red").face("sans-serif-condensed").text("Red Text").close();
textView.setText(html.build());
HTML Tags Supported by TextView
<a href="...">
<b>
<big>
<blockquote>
<br>
<cite>
<dfn>
<div align="...">
<em>
<font color="..." face="...">
<h1>
<h2>
<h3>
<h4>
<h5>
<h6>
<i>
<img src="...">
<p>
<small>
<strike>
<strong>
<sub>
<sup>
<tt>
<u>
<ul>
(Android 7.0+)<li>
(Android 7.0+)
Download
Download the latest AAR or grab via Gradle:
compile 'com.jaredrummler:html-builder:1.0.0'
or Maven:
<dependency>
<groupId>com.jaredrummler</groupId>
<artifactId>html-builder</artifactId>
<version>1.0.0</version>
<type>aar</type>
</dependency>
License
Copyright 2016 Jared Rummler
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.