I am using following line of code to set custom font on widget using remoteView.setTextViewText(R.id.folder_widget_text_view, SS);
but its not working at all, If i used the same code on normal TextView.setText(SS)
method it works.
So is anything wrong in my code or if I miss something.
SpannableStringBuilder SS = new SpannableStringBuilder("hello");
SS.setSpan (new CustomTypefaceSpan(this, "Rosemary.ttf"), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
remoteView.setTextViewText(R.id.folder_widget_text_view, SS);
CustomTypefaceSpan Class
public class CustomTypefaceSpan extends MetricAffectingSpan
{
private static LruCache<String, Typeface> sTypefaceCache =
new LruCache<String, Typeface>(12);
private Typeface mTypeface;
public CustomTypefaceSpan(Context context, String typefaceName)
{
mTypeface = sTypefaceCache.get(typefaceName);
if (mTypeface == null)
{
mTypeface = Typeface.createFromAsset(context.getAssets(), typefaceName);
// Cache the loaded Typeface
sTypefaceCache.put(typefaceName, mTypeface);
}
}
@Override
public void updateMeasureState(TextPaint p)
{
p.setTypeface(mTypeface);
// Note: This flag is required for proper typeface rendering
p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
@Override
public void updateDrawState(TextPaint tp)
{
tp.setTypeface(mTypeface);
// Note: This flag is required for proper typeface rendering
tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
}