简体   繁体   中英

How to save Android edit text content with rich text

I have an EditText where users can set text to bold, italic, etc but I can't figure out how to save that text with styles as .txt file/any other way to save it.If we save as HTML page we can't edit the webview. I use getText but that only returns text and no style info.

I think the best way would be, if you build an own class, which handles the styles. I think, if its a EditText and you can say, part of the text should be bold, so you save something like "10.20.b|" into a temporary var. Later you can handle your styles, parsing the styles-var, split it by "|" and analyze the "10.20.b" which would mean something like "position 10 to position 10+20 is bold". To save it, use XML for example, like:

<?xml version="1.0" encoding="utf-8"?>
<styles>0.4.b|6.2.i|</styles>
<text>This is a wonderful text! OH MY GOD!!!</text>

This would produce:

This is a wonderful text! OH MY GOD!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM