Does anyone know of syntax highlighting libraries which work on Android? I've looked at jsyntaxpane but that doesn't seem to support Android.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I managed to create a syntax highlighter for Android, based on the Prettify. It was easy, actually, when I found the Java Prettify. Just download it (sadly, it is not published for maven) and add its jar to the build path of you application.
The syntax highlighter I created based on it:
The colors of the syntax are hardcoded, but may be also set by i.e. application preferences. In order to display a Java source code in a
TextView
, just do:The Java Prettify library made my application around 50kB bigger.
Hi you can use my CodeEditor
Simply use:
Setup build.gradle (project)
build.gradle (app)
XML DataBinding
XML
I have created an API for text highlighting which can solve your problem.
https://github.com/nakshay/TextHighlighter
This API allows you to pass words and colours specific to words and will return the string which is formatted with html tags which you can send to Html.fromHtml() to get highlighted text. add below Gradle dependency to your module's gradle file.
920 Text Editor (app on Play Store, source on GitHub) uses a combination of WebView and Ace, an embeddable code editor written in JavaScript.
I'm working on an app which is an IDE for Android, I think I'm going the same way.
Well, I did a open-source syntax-highlighting editor for Android:
https://github.com/markusfisch/ShaderEditor
It's quite simple and maybe only suitable for small data, but it's probably a good starting point.
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 sameSpanned
thatTextView
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 theEditText
. I have not seen an open source syntax-highlighting editor for Android -- a few closed-source ones as apps on the Play Store, though.