Rich text in a textview

后端 未结 3 787
时光说笑
时光说笑 2020-12-25 15:13

I need create an \"Info\" for my program. I\'d like fill the info text with several colors, style, fonts, ecc.

I found this: http://www.chrisumbel.com/article/androi

3条回答
  •  眼角桃花
    2020-12-25 15:39

    I wrote a library over the weekend that handles this, I called it a RichTextView.

    The library allows you to format a span of text (make it bold, underline, italic, combination, etc) as well as color it (text color and highlight). In the next release I plan to allow for custom font spans and such as well.

    To use it is simple, just add the following dependency to your gradle file:

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

    Now, let's say you want to make the first four characters bold, you can simply make the following call:

    myRichTextView.formatSpan(0, 4, RichTextView.FormatType.BOLD);
    

    Notice that the end index parameter is not inclusive, so by saying (0 -> 4) we are actually bolding indexes (0 -> 3).

    If you would like to do both bold and underline, use an EnumSet:

    myRichTextView.formatSpan(0, 4, EnumSet.of(RichTextView.FormatType.BOLD, RichTextView.FormatType.UNDERLINE));
    

    For the latest information please see the Github repository linked above, though I will try to update this answer any time it becomes outdated.

提交回复
热议问题