0

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);
Dick Lucas
  • 12,289
  • 14
  • 49
  • 76

1 Answers1

1

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.

CodeJunkie
  • 147
  • 1
  • 5
  • Thank you for the help, but I need to be able to edit the color, size, and font. There must be a way to invoke these textView methods through the remote view, but I am not sure how. – Dick Lucas Aug 01 '13 at 02:39
  • 1
    So to invoke the methods you just call one of the setFloat, setInt, etc. methods from the RemoteViews,... the first argument is the object id inside the RemoteView that you want to change, the second parameter is just the String name of the method from TextView that you want to call, and the third parameter is the argument you're giving to the String method. So what I wrote in the answer above is equal to widgetTextViewLineOne.setTextSize(textSize)... So all you need to do is find the method you need from the TextView class and call it this way – CodeJunkie Aug 01 '13 at 13:39
  • this works for everything except setting the typeface. I can't seem to find a method that supports this. Is there one? – Dick Lucas Aug 02 '13 at 20:14
  • I have discovered that setting the typeface of a widget is not as straightforward. Thank you for your help. More info here: http://stackoverflow.com/questions/4318572/how-to-use-a-custom-typeface-in-a-widget – Dick Lucas Aug 02 '13 at 21:15