0

How can I change the font / typeface of a button in an Android widget? When working with normal view is this no problem:

// Within the app
Button myButton = (Button)rootView.findViewById(R.id.myAppButton);
myButton.setTypeface(someTypeface);

However, when working with a widget, views cannot be accessed directly but only via RemoteViews:

// Widget
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widgetContent);
remoteViews.setTextViewText(R.id.myWidgetButton, "Some Text");

Is it somehow possible to set the typeface of the remote button as well?

Andrei Herford
  • 17,570
  • 19
  • 91
  • 225
  • do you tried this? Typeface font = Typeface.createFromAsset(getAssets(), "robotobold.ttf"); myButton.setTypeface(font); – Muhammad Farhan Arif Mar 04 '21 at 14:31
  • Thanks, but did you read the question? ;-) What you wrote works perfectly when using buttons directly as I described in the first example in my question. However, when working with a widget I **cannot** access the views directly but only via `RemoteViews`.... – Andrei Herford Mar 05 '21 at 11:32

1 Answers1

0

There is no way to change the typeface of TextView in RemoteView.

To check properties that can be changed in RemoteView, in your case just go to Button and TextView classes and check all methods with annotation @android.view.RemotableViewMethod. As you can see, setTypeface don't have an annotation, so it can not be changed in RemoteView anyhow

HeyAlex
  • 1,666
  • 1
  • 13
  • 31