esclkm / RichTextView

A library that enhances the TextView and allows the user to format various spans of the string.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Android Arsenal

RichTextView Library

This library is an enhancement to the TextView component that allows you to style various spans of text inside the view.

Usage

To have access to the library, add the following dependency to your build.gradle:

	compile 'com.androidessence.lib:richtextview:1.0.1'

Format Types

You can apply any combination of the following formats on a span of text:

  • Bold
  • Italic
  • Underline
  • Strikethrough
  • Superscript
  • Subscript

To use these, use one of the following formatSpan methods:

  • formatSpan(int start, int end, FormatType formatType)
    • This method is used to apply a certain format to a span of text in the RichTextView. Start (inclusive) and end (exclusive) are the indexes of the start and end characters to format.
  • formatSpan(int start, int end, EnumSet<FormatType> formatTypes)
    • This method has the same function as the one above, but allows you to apply a number of FormatTypes to this span of text.

Color Format Types

You can apply the following color formats on a span of text:

  • Foreground (the text color)
  • Highlight (the background color of the span)

To use these formats, use the following method:

  • colorSpan(int start, int end, FormatType formatType, int color)
    • This method functions just as the ones above it, the only difference is that it also requires a color to apply to the span. For example, if you wanted to make the first four characters of text blue, you would use colorSpan(0, 5, FormatType.FOREGROUND, Color.BLUE);

Sample

Below is a sample of all the possible formats you can apply to a RichTextView. In this example it is all one string, formatted eight different ways.

Credits & Contact

This library was created by Adam McNeilly with special help from:

It is also released under Android Essence blog.

License

The RichTextView library is available under the MIT License. You are free to modify and enhance it in any way. If you submit a pull request, please add your name into the credits section! :)

About

A library that enhances the TextView and allows the user to format various spans of the string.

License:MIT License


Languages

Language:Java 100.0%