最近在做一个 在notification 添加 天气通知的小部分
发现困扰在 如何给 RemoteView 中的字体 作修改 。
大家都知道 , textView 设置字体 在XML 中 可以 设置 3种 , 而其他字体的设置 需要通过 Typeface 去设置
具体:
将字体放置在asset 文件夹中
Typeface face = Typeface.createFromAsset(this.getAssets(),"helvetica-neue-lt.ttf");
textView.setTypeface(face);
BUT ------------------------------>然后就是重点了
RemoteView 却无法获取到自己view中的textView 。 这个困扰我很久
然后查资料 , 找到这么一个方法
RemoteView中需要改字体的textView ,改使用ImageView
然后
public Bitmap buildUpdate(String time)
{
Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface clock = Typeface.createFromAsset(this.getAssets(),"Clockopia.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(65);
paint.setTextAlign(Align.CENTER);
myCanvas.drawText(time, 80, 60, paint);
return myBitmap;
}
在然后:去使用这个Bitmap
String time = (String) DateFormat.format(mTimeFormat, mCalendar);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);
views.setImageViewBitmap(R.id.TimeView, buildUpdate(time));