This is not especially easy. I have a work-in-progress component in my CWAC-RichEdit project for this.
In the end, you need to be able to apply CharacterStyle
subclasses to the content of the EditText
, typically when the user highlights some text. This involves getting the Spannable
out of the EditText
via getText()
, getting selection information from the EditText
, then applying the span. However:
-
You have to take into account both adding and removing styles
-
Some styles, like bullets or line alignment, are not strictly applied to the highlighted text, but rather to the line containing the highlighted text
-
You need to have some UI to help with this (e.g., additional options in the action mode that pops up when the user highlights text)
I hope (:: crosses fingers ::) to be able to pick up work on my RichEditText
again this fall to push its development along further.
1
solved Make simple text editor in android With Bold Italic and Underline [closed]