I am trying to set BackgroundColorSpan to selected text in my Edit-text. So when i select any text and click on button it will set Background color to that particular text and then i am saving that note to my SDCard with .html format and then again i am retrieving that note to edit again in the same format.
The problem i am facing right now is when i apply BackgroundColorSpan to selected text it show's that string with background color which i applied but once i save that note to my SDCard and re-open, it does not show Background color to that particular string instead of that it show me normal string without background color.
Below is my code Which i used to set Background Color to Edit-text selected area
mSpannable.setSpan(new BackgroundColorSpan(color),startSelection, endSelection, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
and below is code to save my notes to SDcard.
Spanned spannedText = edtNoteDescription.getText();
StringBuilder output = new StringBuilder();
AppHtml.withinHtml(output, spannedText);
File mFile = new File(Environment.getExternalStorageDirectory()
+ File.separator + "MyNote/");
}
File myFile = new File(mFile, "/" + strNoteTitle + ".html/");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(output);
myOutWriter.close();
fOut.close();
With this above code i am successfully able to save my file in HTML format, but i am not getting the string with Background color.
I tried to print that string in Log and then pasted that string in w3School then i get exact result what i expect it to be but in android i don't know why it is not working.
String which i get in Logcat is below
<p><font color ="#7dff00">This</font> <font color ="#ff5100">Is</font>  a  <font color ="#04ff00"><b><font style = "background-color:#2929dd">String</font></b></font>... </p>
You can try this string here which gives perfect result with background color to string but while setting to android Edit-ext i don't know what is happening and it's not setting as i expect it to be.
Edit
Below is code which i used to retrieve text from my SDcard file
Bundle bundle = getIntent().getExtras();
strGetPath = bundle.getString(GlobalClass.notesPath);
filePath = new File(strGetPath);
fileInputStream = new FileInputStream(filePath);
int size = fileInputStream.available();
bytbuffer = new byte[size];
fileInputStream.read(bytbuffer);
fileInputStream.close();
String strGetData = new String(bytbuffer);
Spanned spanHTMLData = AppHtml.fromHtml(strGetData);
LogM.e("===== Getting Data =====" + strGetData);
edtNoteDescription.setText(spanHTMLData);