Android text editor implementation?

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?

+53
android android-edittext richedit
Nov 26 '10 at 8:50
source share
7 answers

I just published my rich text editor under the Apache 2.0 license:

https://github.com/1gravity/Android-RTEditor

enter image description here

+12
Jun 02 '15 at 18:53
source share

I would probably extend both EditText and TableLayout or at least ultimately use most of my source if there were big enough changes I needed to make.

+4
Jan 15 '11 at 6:30
source share

Can you do the following:

  • Manually store content in EditText as its own model (i.e., separating and maintaining the content document and presentation attributes as separate entities).
  • Override the rendering (or drawing) method to create a custom layout on parts of the content document (part of your model) that process non-text characters (for example, bullets with a specific attribute).

It seems to me that if you need to guess with the layout, is it better for you to write it from scratch yourself. From what I remember, the text Edit (and the richt text editor) is great for everything where you are pure text.

+3
Jan 15 2018-11-11T00:
source share

There is a text editor with extended source code EditText called android-richtexteditor , but the code was inexplicably removed in r5. the code is still present in r4 ; just use svn to check r4 or earlier to access it. The code seems to support italics, underlining, color picker, text size, etc.

Also answered these questions: 1 , 2

+2
Dec 15 '11 at 10:19
source share

An extension from EditText is the best choice for you, it supports CharacterSpan and ParagraphSpan.

Check out my app on Google Play: https://play.google.com/store/apps/details?id=com.hly.notes

-one
May 28 '12 at 3:20
source share

Check out this open source Wordpress mobile app for android.It has a very promising Edittext based Richtexteditor.

You can download the source code here.

thank

-one
Sep 09 '13 at 8:56
source share



All Articles