Search code examples
androidwidgetspannablestring

Use SpannableString in Android Home Screen widgets?


Can I use SpannableStrings in a widget's textView? I tried and all it rendered was plain text. I don't know if it is something I'm doing wrong (most likely), or if it just isn't possible for some reason.

Here's the code I'm using (nothing special really...)

 public static void updateWidgetState(Context paramContext, String paramString, Integer appWidgetId) {

    SpannableString majorLabel = new SpannableString("");
    SpannableString minorLabel = new SpannableString("");
    if (position > -1) {
        majorLabel = GetParsedMajorLabel(paramContext);
        minorLabel = GetParsedMinorLabel(paramContext);
    }
    RemoteViews localRemoteViews = buildUpdate(paramContext, paramString, appWidgetId);
    localRemoteViews.setTextViewText(R.id.majorlabel, majorLabel);
    localRemoteViews.setTextViewText(R.id.minorlabel, minorLabel);
 }

Solution

  • If you would like to display formatted text in a TextView, use fromHtml