my app needs to display custom text saved in a bunch of .rtf files inside a TextView. I have searched in different forums and i still don't have a clear solution. It seems pretty easy right? i have developed a few apps like this in iOS and i had no problems displaying .rtf text inside a UITextView as an attributed string. I thought in Android will be easier. Thanks for your time
It seems pretty easy right?
Not especially. Heck, even Windows largely abandoned RTF a decade or so ago.
Option #1: If you were planning on packaging the RTF in the app itself (e.g., as raw resources or assets), get rid of the RTF and use HTML in your app in the first place, using either Html.fromHtml()
and a TextView
or use a WebView
.
Option #2: Find some Java code that can convert RTF to HTML on the fly, then proceed as in Option #1.
Option #3: Find some cross-architecture C/C++ code that can convert RTF to HTML on the fly, add that to your app via the NDK, then proceed as in Option #1.
Option #4: Roll your own RTF parser and a SpannableStringBuilder
to create the formatted Spannable
to load into the TextView
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With