6

它是一个 Android 小部件,我正在尝试向它添加自定义字体。

这是我的代码:

public void updateAppWidget(Context context,AppWidgetManager appWidgetManager,int appWidgetId)  
 {
    String currentTime = (String) df.format(new Date());

    RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget1);
    updateViews.setImageViewBitmap(R.id.widget1label, buildUpdate(currentTime, context));
    appWidgetManager.updateAppWidget(appWidgetId, updateViews);
 }

public Bitmap buildUpdate(String time, Context context) 
{
  Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
  Canvas myCanvas = new Canvas(myBitmap);
  Paint paint = new Paint();
  Typeface clock = Typeface.createFromAsset(context.getAssets(),"batmfo.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;
}  

方法有什么问题buildUpdate()吗?Eclipse 在 Logcat 中没有显示错误。

4

0 回答 0