关于RemoteView 的一些字体的一些问题

最近在做一个 在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));


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值