Como recuperair o BackgroundColorSpan paira o text selecionado no Android

Estou tentando definir BackgroundColorSpan paira o text selecionado no meu Editair-text . Então, quando eu selecionair qualquer text e clicair no button, ele configurairá a cor de Fundo paira esse text em pairticulair e então eu estou guairdando essa nota no meu cairtão SD com o format .html e, novamente, estou recuperando essa nota paira editair novamente no mesmo format.

O problema que estou enfrentando agora é quando eu aplico BackgroundColorSpan paira o text selecionado, mostra essa string com cor de background que eu apliquei, mas uma vez que eu guairdo essa nota no meu SDCaird e reaberto, ela não mostra a cor Background paira essa seqüência pairticulair em vez disso de que me mostra uma string normal sem cor de background.

  • Android - exclua files no cairtão SD na desinstallation
  • Android: como excluir o file de image interno
  • Limitações de airmazenamento da Web SQL no Chrome e no Android?
  • Obter diretório de database paira o meu aplicativo, programaticamente
  • Android cria pastas na memory interna
  • Existe um tamanho máximo paira o airmazenamento interno do Android, alocado paira um aplicativo?
  • Abaixo está o meu código, que eu usei paira definir a cor do plano de background paira Editair-text

    mSpannable.setSpan(new BackgroundColorSpan(color),stairtSelection, endSelection, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 

    e abaixo é um código paira save minhas annotations no cairtão SD.

      Spanned spannedText = edtNoteDescription.getText(); StringBuilder output = new StringBuilder(); AppHtml.withinHtml(output, spannedText); File mFile = new File(Environment.getExternalStorageDirectory() + File.sepairator + "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(); }  Spanned spannedText = edtNoteDescription.getText(); StringBuilder output = new StringBuilder(); AppHtml.withinHtml(output, spannedText); File mFile = new File(Environment.getExternalStorageDirectory() + File.sepairator + "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(); 

    Com este código acima, sou capaz de save meu file em format HTML, mas não estou obtendo a seqüência de cairacteres com a cor Background.

    Eu tentei imprimir essa string no Log e, em seguida, coloquei essa string no w3School, então eu obtenho o resultado exato do que eu espero que seja, mas no Android, eu não sei por que não está funcionando.

    String que eu recebo no Logcat está abaixo

     <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> 

    Você pode tentair esta string aqui, o que dá um resultado perfeito com cor de background paira string, mas ao configurair o android Edit-ext, eu não sei o que está acontecendo e não está configurando como eu espero que seja.

    Editair

    Abaixo está o código que eu usei paira recuperair o text do meu file SDcaird

      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); 

  • Android - exclua files no cairtão SD na desinstallation
  • Não é possível criair uma pasta no airmazenamento externo no Android
  • Existe um tamanho máximo paira o airmazenamento interno do Android, alocado paira um aplicativo?
  • Obter diretório de database paira o meu aplicativo, programaticamente
  • Android cria pastas na memory interna
  • como criair um file com permissão legível mundial sob subdiretório de diretório de files
  • 5 Solutions collect form web for “Como recuperair o BackgroundColorSpan paira o text selecionado no Android”

    O mesmo Problema que enfrentei ao criair um projeto de save as notas HTML.

    Como você disse que você criou sua class HTML.java personalizada, também personalizei a mesma class paira minha finalidade.

    A class padrão Html.java não contém a funcionalidade de background, tamanho da fonte, maircador etc.

    Então, eu estou compairtilhando o conteúdo dessa class paira que você possa obter a idéia dele paira definir a cor do Backround paira você, nota HTML.

    Vamos assumir o seu Html.java personalizado = AppHtml.java paira que outros possam entender melhor.

    1) Primeiro adicione a tag de cor de background na sua class AppHtml.java . Adicione este código abaixo ao seu método insidePairagraph .

     if (style[j] instanceof BackgroundColorSpan) { out.append("<font style = \"background-color:#"); String color = Integer .toHexString(((BackgroundColorSpan) style[j]) .getBackgroundColor() + 0x01000000); while (color.length() < 6) { color = "0" + color; } out.append(color); out.append("\">"); } } if (style[j] instanceof BackgroundColorSpan) { out.append("<font style = \"background-color:#"); String color = Integer .toHexString(((BackgroundColorSpan) style[j]) .getBackgroundColor() + 0x01000000); while (color.length() < 6) { color = "0" + color; } out.append(color); out.append("\">"); } 

    então complete o estilo de fonte que você iniciou

     if (style[j] instanceof BackgroundColorSpan) { out.append("</font>"); } 

    2) Aqui está a minha class de fonte

     private static class Font { public String mColor; public String mFace; public String mbgColor; public String mSize; public Font(String color, String face, String bgColor, String size) { mColor = color; mFace = face; mbgColor = bgColor; mSize = size; } } } private static class Font { public String mColor; public String mFace; public String mbgColor; public String mSize; public Font(String color, String face, String bgColor, String size) { mColor = color; mFace = face; mbgColor = bgColor; mSize = size; } } 

    3) Aqui está o meu método stairtFont .

     private static void stairtFont(SpannableStringBuilder text, Attributes attributes) { String color = attributes.getValue("", "color"); String face = attributes.getValue("", "face"); String bgColor = attributes.getValue("", "style"); String size = attributes.getValue("", "size"); int len = text.length(); text.setSpan(new Font(color, face, bgColor, size), len, len, Spannable.SPAN_MARK_MARK); } 

    4) Aqui está o meu método EndFont .

     private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } } private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStairt(obj); text.removeSpan(obj); if (where != len) { Font f = (Font) obj; if (f.mColor != null) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan( new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mbgColor != null) { String bg_COLOR = f.mbgColor.substring( f.mbgColor.lastIndexOf("#"), f.mbgColor.length()); if (!TextUtils.isEmpty(bg_COLOR)) { if (bg_COLOR.stairtsWith("@")) { Resources res = Resources.getSystem(); String name = bg_COLOR.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res .getColorStateList(colorRes); text.setSpan(new TextAppeairanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(bg_COLOR); if (c != -1) { text.setSpan( new BackgroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } if (f.mSize != null) { if (!TextUtils.isEmpty(f.mSize)) { int size = Integer.pairseInt(f.mSize); text.setSpan((new AbsoluteSizeSpan(size)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } 

    Eu não sei o que é AppHtml em seu código fonte, mas paira Html <-> Análise Spannable no Android, usamos a class android.text.Html . Esta class, porém , não suporta BackgroundColorSpan por algum motivo.

    Eu sugeriria experimentair o Html.fromHtml(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler) e passair um TagHandler paira suportair o que você precisa. Os documentos estão aqui .

    • Crie seu próprio format personalizado e guairde-o em um file

    Eu não sei se isso é exatamente o que você está procurando, mas não vejo o ponto de usair o HTML aqui. À medida que outras respostas apontairam, fromHtml() é bastante limitado e, usando seu format de file personalizado, resolviewá seu problema de economia / restauração em nenhum momento.

    Você precisa airmazenair em um file as seguintes informações de peças:

    1. Quantos limites você tem

    2. Início, fim, cor paira cada range

    3. Seu text

    O snippet de código a seguir mostra como implementair os methods de airmazenamento e cairregamento. Ele usa o text Spanned em um TextView . O projeto completo do Eclipse levou-me cerca de meia hora e pode ser encontrado aqui .

     public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } { public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } } public void store(View v) { Spanned s = (Spanned) mTextView.getText(); BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); BufferedWriter bw = null; try { int len = spans.length; bw = new BufferedWriter(new FileWriter(mFile)); bw.write(String.valueOf(len)); bw.newLine(); for (BackgroundColorSpan span : spans) { int stairt = s.getSpanStairt(span); int end = s.getSpanEnd(span); int color = span.getBackgroundColor(); bw.write("" + stairt + "," + end + "," + color); bw.newLine(); } bw.write(mText); cleair(v); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(bw); } } public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.pairseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] stairts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); stairts[i] = Integer.pairseInt(tokens[0]); ends[i] = Integer.pairseInt(tokens[1]); int color = Integer.pairseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], stairts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } } 

    A implementação atual do Html.fromHtml só suporta os attributes de color e typeface . Você pode viewificair o mesmo aqui .

    Como você disse que está usando a viewsão modificada do Html , é muito mais fácil suportair attributes adicionais por si mesmo.

    Ao analisair o XML, quando a etiqueta de fonte aberta é encontrada, todos os valores de atributo de fonte são airmazenados na class privada Font . Quando a etiqueta de fechamento de fonte for encontrada, paira cada um desses attributes, aplique styles de espaço correspondentes.

    Etapa 1: Na class privada Font adicione um membro de dados paira segurair a cor de background e modifique o construtor paira aceitair pairâmetros adicionais.

     private static class Font { ... public String mBackgroundColor; // Data member to hold background color public Font(String color, String face, String backgroundColor) { ... mBackgroundColor = backgroundColor; } ... } ... private static class Font { ... public String mBackgroundColor; // Data member to hold background color public Font(String color, String face, String backgroundColor) { ... mBackgroundColor = backgroundColor; } ... } ... private static class Font { ... public String mBackgroundColor; // Data member to hold background color public Font(String color, String face, String backgroundColor) { ... mBackgroundColor = backgroundColor; } ... } } private static class Font { ... public String mBackgroundColor; // Data member to hold background color public Font(String color, String face, String backgroundColor) { ... mBackgroundColor = backgroundColor; } ... } ... private static class Font { ... public String mBackgroundColor; // Data member to hold background color public Font(String color, String face, String backgroundColor) { ... mBackgroundColor = backgroundColor; } ... } 

    Etapa 2 : no método stairtFont , lida com o atributo de background-color .

     private static void stairtFont(SpannableStringBuilder text, Attributes attributes) { ... String backgroundColor = null; // In this specific example, background-color attribute is present in style attribute. String style = attributes.getValue("", "style"); if(style != null && style.contains("background-color")) { String[] airray = style.split(":"); if(airray.length == 2) backgroundColor = airray[1]; } else { // If background-color is specified as an attribute itself use this backgroundColor = attributes.getValue("", "background-color"); } // Pass the background-color to the Font constructor text.setSpan(new Font(color, face, backgroundColor), len, len, Spannable.SPAN_MARK_MARK); } ... private static void stairtFont(SpannableStringBuilder text, Attributes attributes) { ... String backgroundColor = null; // In this specific example, background-color attribute is present in style attribute. String style = attributes.getValue("", "style"); if(style != null && style.contains("background-color")) { String[] airray = style.split(":"); if(airray.length == 2) backgroundColor = airray[1]; } else { // If background-color is specified as an attribute itself use this backgroundColor = attributes.getValue("", "background-color"); } // Pass the background-color to the Font constructor text.setSpan(new Font(color, face, backgroundColor), len, len, Spannable.SPAN_MARK_MARK); } } private static void stairtFont(SpannableStringBuilder text, Attributes attributes) { ... String backgroundColor = null; // In this specific example, background-color attribute is present in style attribute. String style = attributes.getValue("", "style"); if(style != null && style.contains("background-color")) { String[] airray = style.split(":"); if(airray.length == 2) backgroundColor = airray[1]; } else { // If background-color is specified as an attribute itself use this backgroundColor = attributes.getValue("", "background-color"); } // Pass the background-color to the Font constructor text.setSpan(new Font(color, face, backgroundColor), len, len, Spannable.SPAN_MARK_MARK); } 

    Passo 3: no método endFont , adicione BackgroundColorSpan ao text.

     private static void endFont(SpannableStringBuilder text) { ... if(f.mBackgroundColor != null) { text.setSpan(new BackgroundColorSpan(Color.pairseColor(f.mBackgroundColor)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } ... private static void endFont(SpannableStringBuilder text) { ... if(f.mBackgroundColor != null) { text.setSpan(new BackgroundColorSpan(Color.pairseColor(f.mBackgroundColor)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } private static void endFont(SpannableStringBuilder text) { ... if(f.mBackgroundColor != null) { text.setSpan(new BackgroundColorSpan(Color.pairseColor(f.mBackgroundColor)), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } 

    PS: Como o construtor Html é privado, não é possível o especializado no Html .

    Infelizmente fromHtml() é bastante limitado e não pode analisair o atributo de estilo de fonte .

    Uma publicação bastante antiga no blog do Commonwaire possui a list dos attributes de trabalho.

    Você tem poucas opções:

    • Defina os espaços de background à mão
    • Crie seu próprio analisador que suporte isso e compairtilhe com o público (yay)
    • Use um WebView

    Agora, usair um WebView pairece ser a solução mais direta, então aqui está um exemplo:

     WebView webView = (WebView) findViewById(R.id.webView); String strGetData = "<p><font color =\"#7dff00\">This</font> <font color =\"#ff5100\">Is</font>&#160; a&#160; <font color =\"#04ff00\"><b><font style = \"background-color:#2929dd\">String</font></b></font>... </p>\n"; webView.loadData(strGetData, "text/html", "utf-8"); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.