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.

谢谢

ng93

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

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

  1. 找到一个Java库,可以语法高亮显示,并使用&LT生成HTML,字体颜色=> (即无CSS)。然后,您可以使用 Html.fromHtml()来创建一个跨区的对象,你可以交给一个的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.

找到一个Java库,可以语法高亮显示并生成任何类型的HTML。然后,您可以显示在的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 就可以了,你必须运行通过语法高亮显示一切以反映变化,无论是在每个按键的基础上,或在打字暂停。或者,你将需要烤的语法更加紧密地强调规则的编辑过程中,所以你能以某种方式逐步调整高亮,而不必重做的全部内容的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.