Android 语法高亮? [英] Android Syntax Highlighting?

查看:39
本文介绍了Android 语法高亮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在 Android 上运行的语法高亮库吗?我看过 jsyntaxpane,但它似乎不支持 Android.

Does anyone know of syntax highlighting libraries which work on Android? I've looked at jsyntaxpane but that doesn't seem to support Android.

推荐答案

对于只读语法高亮,您有两个选择:

For read-only syntax highlighting, you have two options:

  1. 找到一个 Java 库,它可以使用 <font color="">(即,没有 CSS)语法突出显示和生成 HTML.然后,您可以使用 Html.fromHtml() 创建一个 Spanned 对象,您可以将其传递给 TextView.

  1. Find a Java library that can syntax highlight and generate HTML using <font color=""> (i.e., no CSS). You can then use Html.fromHtml() to create a Spanned object which you can hand to a TextView.

找到一个可以语法高亮并生成任何类型的 HTML 的 Java 库.然后您可以在 WebView 中显示它.这似乎是 android-codepad 项目链接到的评论者.

Find a Java library that can syntax highlight and generate any sort of HTML. You can then display that in a WebView. This appears to be what the android-codepad project a commenter linked to does.

如果您正在为编辑器寻找语法高亮,那要困难得多.虽然 EditText 可以采用与 TextView 相同的 Spanned,但您必须通过语法高亮器运行所有内容以反映更改,无论是在每个- 击键基础,或在打字暂停后.或者,您需要将语法突出显示规则更紧密地融入编辑过程,这样您就可以以某种方式逐步调整突出显示,而不必重做 EditText 的全部内容.我还没有看到适用于 Android 的开源语法高亮编辑器——不过,在 Play 商店中看到了一些作为应用程序的封闭源代码编辑器.

If you are seeking syntax highlighting for an editor, that is significantly more difficult. While EditText can take the same Spanned that TextView can, you would have to run everything through the syntax highlighter to reflect changes, either on a per-keystroke basis, or after a pause in typing. Or, you would need to bake the syntax highlighting rules much more tightly to the editing process, so you can somehow incrementally adjust the highlighting without having to redo the entire contents of the EditText. I have not seen an open source syntax-highlighting editor for Android -- a few closed-source ones as apps on the Play Store, though.

这篇关于Android 语法高亮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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