我使用了自定义文本的小部件但我知道小部件不能支持自定义文本意味着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));
现在我的问题是,我的小部件显示我什么都没有黑暗没有任何东西显示在小部件没有任何错误产生可以任何人帮助我?
答案 0 :(得分:1)
我认为您的以下代码存在问题
remoteViews.setTextColor(R.id.textViewGuj, settings.getInt(
Const.Mean_Pref_Color_Key,
context.getResources().getColor(R.color.orange)));
只需删除此行,因为您使用的是ImageView,而ImageView
没有任何TextColor属性希望工作正常:)