Question

I have a widget that consists of only one textView, and I want to be able to edit the color, size, and font of the textView based on user preference. But it seems the only way to update a widget is by using a RemoteView. This poses two problems for me:

1.) This only allows editing of the text, color, and size (but editing the size is only available in API 16, I am supporting 11 and up.)

2.) This does not allow me to edit the font.

Luckily, the textView class http://developer.android.com/reference/android/widget/TextView.html allows me to do everything I want. Is there any way I can invoke these methods on my textView in my widget layout, without being restricted by the RemoteView class.

All help is greatly appreciated, and here is my code so far.

RemoteViews v = new RemoteViews(getPackageName(), R.layout.widget);
v.setTextViewText(R.id.widgetTextViewLineOne, widgetTextViewLineOneText);
v.setTextColor( R.id.widgetTextViewLineOne, widgetColor);
manager.updateAppWidget(awID, v);
Was it helpful?

Solution

If all you want is to set the testView text size in low APIs use this code:

  float textSize = 30.0f
  v.setFloat(R.id.widgetTextViewLineOne, "setTextSize", textSize);

The float-->textSize is a number that scales the text size depending on the device that runs the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top