Build valid HTML for Android TextView

Overview

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.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.
Comments
  • clickable text or link ?

    clickable text or link ?

    I really appreciate effort you have done to create a Html Builder its nice library.I would like to have feature to make link clickable with appropriate listener interface provided in builder.

    opened by kirtan007 2
  • not showing images

    not showing images

    does not load images sample image : <a href=\"http://www.sakhtemanchi.com/%d8%b1%d9%86%da%af-%d9%86%d8%b3%d9%88%d8%b2-%da%86%db%8c%d8%b3%d8%aa%d8%9f/\">

    opened by mjalijani 1
  • Escaping Text and Support For String Resources

    Escaping Text and Support For String Resources

    Hi can you provide support for String Res in text() function.When we pass the text / append it please provide parameter if we want to escape the text with Html.escapeHtml. When we pass symbols it does not escape automatically and spoils the html text . It would be very nice if you provide Boolean to set if we want to escape the text when we append it.

    opened by kirtan007 1
  • Only add release builds

    Only add release builds

    Issue:

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':library:uploadArchives'.
    > Could not publish configuration 'archives'
       > A POM cannot have multiple artifacts with the same type and classifier. Already have MavenArtifact html-builder:jar:jar:binary, trying to add MavenArtifact html-builder:jar:jar:binary.
    

    Fix and explanation:

    It was going through all variants, adding "debug" and "release" to the archives wit the same "classifier" and type(jar)

    opened by jaredsburrows 1
  • Add jar to archives

    Add jar to archives

    • Add compiled Jar Task for debug and release variants
    • Output names: library-debug.jar and library-release.jar just like the output names for the AARs: library-debug.aar and library-release.aar
    opened by jaredsburrows 0
  • Publish Jar for Java Projects

    Publish Jar for Java Projects

    See https://github.com/BlueWalker/BeaconLib/blob/master/build.gradle#L35

    By added the jar artifact, we should be able to use the jar by doing the following:

    compile 'com.jrummyapps:html-builder:1.0.0@jar'   // JAR
    compile 'com.jrummyapps:html-builder:1.0.0'       // AAR
    
    enhancement 
    opened by jaredsburrows 0
  • Hi

    Hi

    Hello. Can you please add style.textAlign (Attribute.Align.END) because sometimes style.textAlign (Attribute.Align.RIGHT) does not work

    <dіv style="text-align: end;"> Some text need right</dіv>

    opened by Viktor9397 0
Owner
Jared Rummler
ᴇᴍʙʀᴀᴄᴇ ᴛʜᴇ ᴄʜᴀɴɢᴇ ᴏʀ ʙᴇ ʟᴇғᴛ ʙᴇʜɪɴᴅ ^ↀᴥↀ^
Jared Rummler
A simple and flexible Checked TextView or Checkable TextView

CheckableTextView Checkable TextView [KOTLIN] ⚡ A simple and flexible Checked TextView or Checkable TextView written in Kotlin ⚡ What's New Animation

null 110 Nov 20, 2022
Mentions-TextView - Make Mentions and hashtags clickable in Textview

Mentions Textview Custome Textview with Mentions and hashtags being clickable. D

null 2 Jan 9, 2022
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

Feras Alnatsheh 1k Dec 20, 2022
Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Manabu S. 4k Dec 28, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
Android experiment showing a sinking TextView

Titanic is an Android experiment reproducing this effect.

Romain Piel 1.8k Dec 15, 2022
Advanced Android TextView

Advanced Android TextView Companion app for my Advanced Android TextView talk, demostrating: Animated CompoundDrawable Text shadow Custom font Non-bre

Chiu-Ki Chan 1.2k Dec 9, 2022
This is based on an open source autosizing textview for Android.

SizeAdjustingTextView This is based on an open source autosizing textview for Android I found a few weeks ago. The initial approach didn't resize mult

Elliott Chenger 255 Dec 29, 2022
An extension of Android's TextView, EditText and Button that let's you use the font of your choice

AnyTextView (deprecated) Note: AnyTextView is no longer being maintained. I recommend replacing AnyTextView with the Calligraphy library instead. Frus

Hans Petter Eide 165 Nov 11, 2022
Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Provides easy means to validate with dependencies.

android-formidable-validation Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Pr

Linden 147 Nov 20, 2022
Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText

Simple Linkable Text Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText Installation Gradle Add dependenc

Aditya Pradana Sugiarto 76 Nov 29, 2022
Lightweight android library for highlighting sections of a textview, with optional callbacks.

Linker Lightweight android library for highlighting Strings inside of a textview (ignoring case), with optional callbacks. Language: Java MinSDK: 17 J

Josh Gainey 35 Apr 30, 2022
Android slanted TextView.

SlantedTextView Android slanted TextView . 中文版 Preview Gradle compile 'com.haozhang.libary:android-slanted-textview:1.2' XML Layout <com.haozhang.lib.

Hand Zhang 2.2k Dec 26, 2022
() An Android TextView with a shimmering effect

Shimmer for Android This library is DEPRECATED, as I don't have time to mainatin it anymore. But feel free to go through the code and copy that into y

Romain Piel 2k Jan 7, 2023
An Android TextView that always displays an auto refreshing relative time span with respect to a reference time

android-ago This library provides RelativeTimeTextView, a custom TextView that takes a reference time and always displays the relative time with respe

Kiran Rao 658 Dec 21, 2022
a super textview for android

SuperTextView 重磅推出SuperTextView2.x版本,属性参数相比1.x有些变化,1.x的用户升级2.x的时候请注意 1、功能描述 SuperTextView是一个功能强大的View,可以满足日常大部分布局样式,开发者可已自行组合属性配置出属于自己风格的样式!可能描述起来没有概念

Allen 3.7k Dec 29, 2022
ExpandableTextView - Read More TextView for Android

ExpandableTextView Read More TextView for Android Usage Gradle dependencies { implementation 'com.wayne.expandabletextview:expandable-textview:1.1

You kwangwoo 31 Oct 12, 2022
Animation effects to text, not really textview

HTextView Animation effects with custom font support to TextView see iOS Effects see Flutter Effects Screenshot type gif Scale Evaporate Fall Line Typ

hanks 5.5k Jan 5, 2023
A TextView that automatically resizes text to fit perfectly within its bounds.

AutoFitTextView A TextView that automatically resizes text to fit perfectly within its bounds. Usage dependencies { compile 'me.grantland:autofitt

Grantland Chew 4.2k Jan 1, 2023