0

I have an app widget that has a TextView I need to change textColor, shadowColor, and gravity of.

While I can easily set textColor with view.settextColor() and Gravity with view.setInt(); to the RemoteView, i can't find a way to set shadowColor.

The shadow's color depends on the text's color selected (black on withe or white on black only) and it is needed for legibility.

I tried inflating different layouts with both text and shadow colors already set and it worked, but the widget's definition XML requires a single initial layout to be declared and I'd end up with two identical id's for its textViews, so I don't know if i should.

If i can't set it programmatically what options do i have left?

Thanks.

Iker Hoëk
  • 242
  • 3
  • 14
  • Did you have any luck with that? setShadowColor or sth. like that still doesn't seem to be supported in 2021... – goldensoju Nov 14 '21 at 10:44

1 Answers1

0
public Bitmap buildUpdate(String time) 
{
   Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
   Canvas myCanvas = new Canvas(myBitmap);
   Paint paint = new Paint();       
   paint.setAntiAlias(true);
   paint.setSubpixelText(true);       
   paint.setStyle(Paint.Style.FILL);
   paint.setColor(Color.WHITE);
   paint.setTextSize(65);
   paint.setTextAlign(Align.CENTER);
   myCanvas.drawText(time, 80, 60, paint);
   return myBitmap;

}

String time = (String) DateFormat.format(mTimeFormat, mCalendar);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);
views.setImageViewBitmap(R.id.TimeView, buildUpdate(time));

Source : How to use a custom typeface in a widget?

Jayakrishnan
  • 4,457
  • 29
  • 29