【问题标题】:Widget with custom text support具有自定义文本支持的小部件
【发布时间】:2013-08-23 10:36:58
【问题描述】:

我已经为小部件使用了自定义文本,但我知道小部件不支持自定义文本意味着 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));

现在我的问题是我的小部件没有显示任何东西它变成深黑色小部件中没有任何显示没有任何错误正在生成任何人可以帮助我吗?

【问题讨论】:

    标签: java android android-widget widget


    【解决方案1】:

    我认为你下面的代码有问题

          remoteViews.setTextColor(R.id.textViewGuj, settings.getInt(
                Const.Mean_Pref_Color_Key,
                context.getResources().getColor(R.color.orange)));
    

    只需删除此行,因为您使用的是 ImageView 并且 ImageView 没有任何 TextColor 属性

    希望一切顺利:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多