Issue
Does anyone know of syntax highlighting libraries which work on Android? I've looked at jsyntaxpane but that doesn't seem to support Android.
Solution
For read-only syntax highlighting, you have two options:
Find a Java library that can syntax highlight and generate HTML using
<font color="">
(i.e., no CSS). You can then useHtml.fromHtml()
to create aSpanned
object which you can hand to aTextView
.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 theandroid-codepad
project a commenter linked to does.
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.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.