android 字体

来源:互联网 发布:淘宝客服英文怎么说 编辑:程序博客网 时间:2024/05/17 04:45

http://wenku.baidu.com/view/2d24be10cc7931b765ce155b.html


remoteview 的字体问题:http://blog.sina.com.cn/s/blog_7d22784d0101kfjm.html

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

(2013-05-09 15:54:14)
转载
标签:

it

android

分类:android理解

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

原创粉丝点击