1
:數字時鐘如何創建自定義圖像我想建立這樣一個digitalclock數字時鐘小時的Android
https://play.google.com/store/apps/details?id=com.bacastudio.lcd
我嘗試使用本教程中添加字體,但它不工作: https://github.com/browep/AndroidCustomFontWidgets/blob/master/AndroidManifest.xml
感謝所有幫助:)
我有問題的字體,在Eclipse中一切正常,任何錯誤,但是當我運行它什麼都沒有發生。
package org.me;
public class Euro2012cc extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
context.startService(new Intent(context, UpdateService.class));
}
public static class UpdateService extends Service {
@Override
public void onStart(Intent intent, int startId) {
// Build the widget update for today
RemoteViews view = buildUpdate(this);
// Push update for this widget to the home screen
ComponentName thisWidget = new ComponentName(this, Euro2012cc.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, view);
}
public RemoteViews buildUpdate(Context context) {
RemoteViews view = null;
view = new RemoteViews(context.getPackageName(), R.layout.main);
String time = "blablabla";
view.setImageViewBitmap(R.id.test, buildUpdateTime(time));
return view;
}
@Override
public IBinder onBind(Intent intent) {
// We don't need to bind to this service
return null;
}//ibinder
public Bitmap buildUpdateTime(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(),"TechnoHideo.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(15);
paint.setTextAlign(Align.CENTER);
myCanvas.drawText(time, 80, 60, paint);
return myBitmap;
}
}
}
我如何可以加載字體? getAsset不能在AppWidget中工作:( – Azor 2012-03-22 14:31:52