如何在TextView中显示.rtf文件? [英] How to display .rtf file inside TextView?

查看:69
本文介绍了如何在TextView中显示.rtf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要显示保存在TextView内的一堆.rtf文件中的自定义文本.我在不同的论坛中搜索过,但仍然没有明确的解决方案.看起来很容易吧?我已经在iOS中开发了一些类似的应用程序,并且在UITextView中将.rtf文本显示为属性字符串没有问题.我以为在Android中会更容易.谢谢您的时间

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?

不是特别.哎呀,甚至在十年前的 Windows 中,也基本上放弃了RTF.

Not especially. Heck, even Windows largely abandoned RTF a decade or so ago.

选项1:如果您打算将RTF打包在应用本身中(例如,作为原始资源或资产),请摆脱RTF并首先使用在应用中使用HTMLHtml.fromHtml() TextView 或使用 WebView .

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.

选项2:查找一些Java代码,这些Java代码可以即时将RTF转换为HTML,然后按照选项1进行操作.

Option #2: Find some Java code that can convert RTF to HTML on the fly, then proceed as in Option #1.

选项3:找到一些可以将RTF即时转换为HTML的跨体系结构C/C ++代码,然后通过NDK将其添加到您的应用中,然后按照选项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.

选项4:滚动您自己的RTF解析器和一个 SpannableStringBuilder ,以创建格式化的 Spannable ,以加载到 TextView 中.

Option #4: Roll your own RTF parser and a SpannableStringBuilder to create the formatted Spannable to load into the TextView.

这篇关于如何在TextView中显示.rtf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆