I am wondering if there are good opportunities for implementing a rich text editor in Android. Please note that I'm talking about a rich text editor that can be used in an Android application, and not embedded in a web page using HTML and Javascript.
My requirements:
- Basic formatting (color, fonts, emphasis, bold, italics, underline, etc.).
- Hyperlinks
- Inline Images
- Bullet lists and numbered lists
- Inline table (only the contents inside the cell are edited, not the table structure)
As you can see, this is almost something similar to a typical RichEdit control on Windows.
Here are some of the efforts (research and prototyping) that I have made so far:
Using WebView
I tried using a WebView control to load an HTML fragment with one. The content becomes editable, and since it is HTML, I suppose it can satisfy most of my requirements. But he has a few questions:
- (deadly) No text. The user will not know where his entered characters will be inserted.
- The on-screen on-screen keyboard is not displayed by default. There is a trick that the user must press the "Menu" button for a long time to bring up the keyboard. But I think this is a very bad user interface. In addition, the screen layout is incorrectly reordered, and the text entry point will sometimes be closed by the keyboard.
Using EditText
I tried using the EditText control. It seems to support some level of editing extended text (color, fonts, bold, italics, underline, inline images, bullet lists). But I still canβt understand how I can implement the following requirements:
- Manage the symbol of the bullet symbol (dot, circle, dash, arrow, star, etc.).
- Numbered list (1., 2., 3., etc.)
- Table
By the way, I saw that there are several Span classes, but I'm not sure that they can be of any help ... And http://developer.android.com does not provide a lot of useful information about them.
So how can I implement a rich text editor on Android? Can I extend EditText and add new features? Or should I do something from scratch - expanding the view and realizing everything by itself? For a later version (View extension), I donβt even know how to show text carriages and blink, not to mention carriage movement with user input.
Now I'm desperate ... Any hints?
Thank!
-Tony
(EDIT)
After some further research, it looks like the EditText extension would be my best bet. I somehow figured out how to use these Span classes and I think that I should be able to do most of the tricks using (expanding) them.
For example, extending BulletSpan and overriding drawLeadingMargin should give me control over bullet options. The LeadingMarginSpan extension should help me on a numbered list.
As for the table, my initial plan is to extend the LineBackgroundSpan and draw all the borders of the table in an override to drawBackground. However, I still need to figure out how to place all the text in the cells of the table and correctly handle the movement and carriage selection. Suggestions?