如何更改 Android 小部件中按钮的字体/字体?使用正常视图时,这没问题:
// Within the app
Button myButton = (Button)rootView.findViewById(R.id.myAppButton);
myButton.setTypeface(someTypeface);
但是,使用小部件时,无法直接访问视图,只能通过
RemoteViews
:
// Widget
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widgetContent);
remoteViews.setTextViewText(R.id.myWidgetButton, "Some Text");
是否也可以设置远程按钮的字体?
无法更改RemoteView中TextView的字体。
要检查可在 RemoteView 中更改的属性,请转到
android.widget.Button
和 android.widget.TextView
类,并检查带有注释 @android.view.RemotableViewMethod
的所有方法。正如你所看到的,setTypeface方法没有注释,所以它不能在RemoteView中更改。