In this tutorial, we will take a look into displaying HTML text in Android TextView.

Many times while you design an application, you may encounter a place where you will like to use HTML content in your screen. This may be to display a static “eula” or “help” content. In android there is a lovely class android.text.HTML that processes HTML strings into displayable styled text. Currently android doesn’t support all HTML tags.

Android API documentation does not stipulate what HTML tags are supported. Currently android seems support the following HTML tags to be rendered on TextView.

[box style=”4″]

<a href=”…”> <b>,  <big>, <blockquote>, <br>, <cite>, <dfn>
<div align=”…”>,  <em>, <font size=”…” color=”…” face=”…”>
<h1>,  <h2>, <h3>, <h4>,  <h5>, <h6>
<i>,  <img src=”…”>,  <p>, <small>
<strike>,  <strong>, <sub>, <sup>, <tt>, <u>[/box]

From HTML method returns displayable styled text from the provided HTML string. As per android’s official Documentations any tags in the HTML will display as a generic replacement image which your program can then go through and replace with real images.

Html.formHtml method takes an Html.TagHandler and an Html.ImageGetter as arguments as well as the text to parse. We can parse null as for the Html.TagHandler but you’d need to implement your own Html.ImageGetter as there isn’t a default implementation. The Html.ImageGetter needs to run synchronously and if you’re downloading images from the web you’ll probably want to do that asynchronously. But in my example I am using the images from resources to make my ImageGetter implementation simpler.

Display HTML in Android TextView

Create a new file inside layout folder and name it as main_layout.xml and paste the following code.


<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="Your HTML text Below"/>



Here is our Activity code, where we will render HTML tags in TextView.

package com.javatechig.example.ui;

import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

private final String htmlText = "<body><h1>Heading Text</h1><p>This tutorial " +
            "explains how to display " +
            "<strong>HTML </strong>text in android text view.&nbsp;</p>" +
            "<img src=\"hughjackman.jpg\">" +
            "<blockquote>Example from <a href=\"\">" +

protected void onCreate(Bundle savedInstanceState) {

          TextView htmlTextView = (TextView)findViewById(;
          htmlTextView.setText(Html.fromHtml(htmlText, new ImageGetter(), null));


private class ImageGetter implements Html.ImageGetter {

public Drawable getDrawable(String source) {
        int id;
        if (source.equals("hughjackman.jpg")) {
               id = R.drawable.hughjackman;
        else {
            return null;

       Drawable d = getResources().getDrawable(id);
       return d;


Here is the output of the above code

HTML in Android TextView

This article is about: Code Sample,


A blogger, a bit of tech freak and a software developer. He is a thought leader in the fusion of design and mobile technologies. He is the author of Xamarin Mobile Application Development for Android Book (, DZone MVB and founder of


Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.