Build valid HTML for Android TextView
Java
Latest commit c342540 Dec 30, 2016 @jaredrummler jaredrummler Artifact publishing
Permalink
Failed to load latest commit information.
art Update demo Dec 22, 2016
demo Update demo Dec 23, 2016
gradle Artifact publishing Dec 30, 2016
library Artifact publishing Dec 30, 2016
.gitignore Initial commit Dec 22, 2016
LICENSE Add license file Dec 22, 2016
README.md Update README.md Dec 22, 2016
build.gradle Initial commit Dec 22, 2016
gradle.properties Initial commit Dec 22, 2016
gradlew Initial commit Dec 22, 2016
gradlew.bat Initial commit Dec 22, 2016
settings.gradle Initial commit Dec 22, 2016

README.md

HTML Builder

Maven Central License API Twitter Follow

Build valid HTML for Android TextView.

Screenshot

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.jrummyapps:html-builder:1.0.0'

or Maven:

<dependency>
  <groupId>com.jrummyapps</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.