[英]how to set Custom font for Widget?
我想在小部件中為TextView設置自定義字體,如何?
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.weather_widget);
views.setTextViewText(R.id.txv_widget_location, "my text");
只需將xyz.ttf替換為您選擇的字體即可。
public Bitmap createBitmap(String texttoshow)
{
Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_8888);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface weatherwidget = Typeface.createFromAsset(this.getAssets(),"xyz.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(weatherwidget);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(65);
paint.setTextAlign(Align.CENTER);
myCanvas.drawText(texttoshow, 80, 60, paint);
return myBitmap;
}
上面的代碼將字體和文本應用於圖像視圖。
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.weather_widget);
views.setImageViewBitmap(R.id.txv_widget_location, createBitmap("my_text"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.