title: Implementing a rich text editor in Android?
body: <p>I am wondering if there are any good options to implement a <strong>rich text editor</strong> in Android. Please note I am talking about a rich text editor that can be used in an Android application, not the one embedded in a web page using HTML and Javascript.</p>
  
  <p>My requirements are:</p>
  
  <ul>
  <li>Basic formatting (color, fonts, highlight, bold, italic, underline, etc.)</li>
  <li>Hyperlinks</li>
  <li>Inline images</li>
  <li>Bullet lists and numbered lists</li>
  <li>Inline table (only the contents inside a cell is editable, not the table structure)</li>
  </ul>
  
  <p>As you can see, this is pretty much something quite similar to a typical RichEdit control on Windows.</p>
  
  <p>Here are some efforts (investigation &amp; prototyping) I have made so far:</p>
  
  <h2>Using WebView</h2>
  
  <p>I have tried using a WebView control to load an HTML fragment with one . The content becomes editable and as it is HTML, I suppose it can meet most of my requirements. But it has several issues:</p>
  
  <ul>
  <li>(deadly) No text caret. The user will have no idea where his/her typed characters will be inserted.</li>
  <li>The on-screen soft keyboard is not visible by default. There is a trick that the user has to long-press the Menu button to bring up the keyboard. But I think this is a very bad user experience. Besides, the screen layout is not properly rearranged and the text inserting point sometimes will be covered by the keyboard.</li>
  </ul>
  
  <hr>
  
  <h2>Using EditText</h2>
  
  <p>I have tried using the EditText control. It seems to support some level of rich text editing (color, fonts, bold, italic, underline, inline images, bullet lists). But I still cannot figure out how I can implement the following requirements:</p>
  
  <ul>
  <li>Control the appereance of the bullet symbol (dot, circle, dash, arrow, star, etc.)</li>
  <li>Numbered list (1., 2., 3., etc.)</li>
  <li>Table</li>
  </ul>
  
  <p>BTW, I have seen there are several *Span classes out there but I am not sure if they can be any help... And the <a href="http://developer.android.com" rel="noreferrer">http://developer.android.com</a> does not provide much useful information about them.</p>
  
  <hr>
  
  <p>So, how on earth can I implement a rich text editor on Android?
  Can I extends the EditText and add my new functionalities? Or should I do something from scratch - extends the View and implement everything by myself? For later option (extending View), I actually even don't know how to show a text caret and blink it, not mentionging moving the caret with user typing.</p>
  
  <p>I am desperate now... Any hints?</p>
  
  <p>Thanks!</p>
  
  <p>-Tony</p>
  
  <hr>
  
  <h2>(<em>EDIT</em>)</h2>
  
  <p>After some further investigation, it looks like extending EditText would be my best bet. I somehow figured out how to use those Span classes and guess I should be able to do most of the tricks by using (extending) them.</p>
  
  <p>For example, extending the BulletSpan and overriding drawLeadingMargin should give me the control of the bullet appereances. Extending the LeadingMarginSpan should help me on the numbered list.</p>
  
  <p>As to the table, my initial plan is to extend the LineBackgroundSpan and draw all the table borders in the drawBackground override. However, I still need to figure out how to layout all the text in the table cells and properly handle the caret movement and selection. Suggestions?</p>