我已经为小部件使用了自定义文本,但我知道小部件不支持自定义文本意味着 TextView 与我们的 TTF 文件
所以我用下面的代码来支持
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
......................
remoteViews.setTextColor(R.id.textViewGuj, settings.getInt(
Const.Mean_Pref_Color_Key,
context.getResources().getColor(R.color.orange)));
remoteViews.setTextViewText(R.id.textViewEng, engWord);
remoteViews.setImageViewBitmap(R.id.textViewGuj,
buildUpdate(meaning));
remoteViews.setOnClickPendingIntent(R.id.LinearLayout01,
pendingIntent1);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
}
public Bitmap buildUpdate(String time)
{
Bitmap myBitmap = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_4444);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface clock = Typeface.createFromAsset(mContext.getAssets(),"fonts/Gujarat.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(settings.getInt(
Const.Mean_Pref_Color_Key,
mContext.getResources().getColor(R.color.orange)));
//paint.setColor(Color.WHITE);
paint.setTextSize(20);
paint.setTextAlign(Align.CENTER);
myCanvas.drawText(time, 80, 60, paint);
return myBitmap;
}
并用于更新 ImageView
remoteViews.setImageViewBitmap(R.id.textViewGuj,
buildUpdate(meaning));
现在我的问题是我的小部件没有显示任何东西它变成深黑色小部件中没有任何显示没有任何错误正在生成任何人可以帮助我吗?