Style your text with Snippety
Wondering how to use customized text styles in your Android app but fed up of wrapping your text with Html.fromHtml()
? Essentially, Html.fromHtml()
internally converts the HTML text to Spanned
and then set it to the TextView
. Here’s the good news, you can now directly use Snippety to do this without the overhead. And you’ll finally get the hang of using Spannable
.
Its a wrapper class on top of SpannableStringBuilder
with utility methods for android and custom spans. You can trust Snippety and Truss (by Jake Warton) to write cool text snippets which might be a pain in the neck otherwise.
Installation ⬇️
To add Snippety to your project, simply follow the instructions provided on the JitPack website.
You can look up at the Snippety github sample for reference.
How to use 👣
Using Truss
Truss
returns a CharSequence
. There are 2 ways of using it:
1. Nested append : pushSpan(Span)
, append(String)
and popSpan()
2. Inline append : append(String, Span)
Using Snippety
Snippety
could be thought of as a collection of different span(s) which are anything but the actual span(s).
You can also add multiple span attributes at a time.
Finally
Set the CharSequence
returned by Truss
to your `TextView`.
Attach OnClickListener
to some text:
Snippety Demo 🎃
Here is how you can achieve the demo screenshot attached
A special thanks to my friend and colleague Hussein Aladeen for helping me build this library and a token of gratitude to our Android team lead Julien Veneziano for the inspiration.
Please 👏🏻 if you think this is helpful. Happy coding! 😊