我有一个自定义数字时钟小部件,我想使用自定义字体。我已经掌握了一些可以帮助我的代码,但是我需要有关如何使用它的帮助。这是方法:
public static RemoteViews buildUpdate(Context context)
{
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
Bitmap myBitmap = Bitmap.createBitmap(100, 50, Bitmap.Config.ARGB_4444);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface clock = Typeface.createFromAsset(context.getAssets(),"Clockopia.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(15);
myCanvas.drawText("Test", 0, 0, paint);
views.setImageViewBitmap(R.id.TimeView, myBitmap);
return views;
}
这是我的更新服务:
private void update() {
mCalendar.setTimeInMillis(System.currentTimeMillis());
final CharSequence time = DateFormat.format(mTimeFormat, mCalendar);
final CharSequence date = DateFormat.format(mDateFormat, mCalendar);
final CharSequence day = DateFormat.format(mDayFormat, mCalendar);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);
views.setTextViewText(R.id.Day, day);
views.setTextViewText(R.id.Date, date);
buildUpdate(this);
ComponentName widget = new ComponentName(this, DigiClock.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(widget, views);
}
如何使用buildUpdate方法显示时间?