Line numbers, code highlighting in TextView

I am working on an “IDE” for Android - it can be useful for editing short scripts / quick file setup. At the moment, I'm just using a simple EditText, but I want to add some functions, for example, line numbering on the left side of the EditText and code selection.

Does anyone have any suggestions on how to approach this? To highlight the code, I assume that I will need to write my own subclass of EditText. For line numbering, could I have a thin vertical TextView that has the same text size as EditText ??

Yes, I know that editing code on a mobile-sized screen is painful.

Thank!

+3
source share
1 answer

The email application uses the html view ( android.webkit.WebView ) to wrap even text messages in html. Perhaps rendering the code in html and rendering it in a WebView would be a good way to get syntax highlighting.

For line numbering, the thin TextView next to the EditText seems reasonable. You might want to encapsulate it in your own View class, which handles both subheadings - and allows you to turn line numbers on and off (and maybe does other nice things, such as keeping the text size equal)

I think the idea for Android is a good idea. It would be nice to be able to code on a plane without having to use the tray table =)

+2

Source: https://habr.com/ru/post/1761722/


All Articles