How to display .rtf file inside TextView?

℡╲_俬逩灬. 提交于 2019-12-22 03:52:51

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/23208166/how-to-display-rtf-file-inside-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!