0

I wanted to highlight part of my edit text like so:-

mySpannablestring.setSpan((new 
BackgroundColorSpan(color)),0,mySpannablestring.length(),0);

//then set to editext

editext.setText(mySpannablestring);

I saved it as a String to database using HTML :-

String todatabase = Html.toHtml(editext.getText());

//then saved the String in sqlite.

Basically the code saves for basic rich-text operations like bold,italic and underline but in that highlight operation it saved only on API 25 not even in API 23 .The intended text gets highlighted successfully but isn't saved .

P-Gn
  • 23,115
  • 9
  • 87
  • 104
Omar Boshra
  • 447
  • 7
  • 21

1 Answers1

0

Sure it will not be saved. You'r trying to save String whitch is not Spannable. If you really want to save SpannableString you need some way to serialize and then deserialize value that you receive from textView.getText(). And note, that getText() returns CharSequence and not String. And this CharSequense basically can be anything.

Ekalips
  • 1,473
  • 11
  • 20
  • So do you mean html doesn't keep that format?. I used **to.html** for saving in the String then **from.html** to convert it to spanned. This works for bold,italic and underline .So what should I use for this?.This problem also exists when changing text size, – Omar Boshra Jun 30 '17 at 17:02