1
私はデジタル時計ウィジェットを持っており、カスタムフォントを使用して時刻を表示したいと考えています。私はそれがリモートビューではできないことを知っているので、カスタムフォントをビットマップにレンダリングし、それをリモートビューを介してイメージビューにプッシュするコードをいくつか手に入れました。しかし、私はそれを動作させることができません。これまでのコードです:カスタムフォントを使用して時間を表示する際の問題
public Bitmap buildUpdate(String time)
{
RemoteViews views = new RemoteViews(this.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(this.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(time, 0, 20, paint);
views.setImageViewBitmap(R.id.TimeView, myBitmap);
return myBitmap;
}
private void update() {
mCalendar.setTimeInMillis(System.currentTimeMillis());
final CharSequence date = DateFormat.format(mDateFormat, mCalendar);
final CharSequence day = DateFormat.format(mDayFormat, mCalendar);
// final CharSequence time = DateFormat.format(mTimeFormat, mCalendar);
String time = (String) DateFormat.format(mTimeFormat, mCalendar);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);
views.setTextViewText(R.id.Day, day);
views.setTextViewText(R.id.Date, date);
// views.setTextViewText(R.id.Time, time);
buildUpdate(time);
ComponentName widget = new ComponentName(this, DigiClock.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(widget, views);
}
何か助けていただければ幸いです。
"しかし、私はそれを動作させることができません。" - あなたが本当に助けを期待しているなら、あなたはあなたの問題を説明するのにもっと良い仕事をする必要があります。 – CommonsWare