【发布时间】:2021-03-04 10:40:24
【问题描述】:
如何更改 Android 小部件中按钮的字体/字样?当使用 normal 视图时这没问题:
// 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");
是否也可以设置遥控按钮的字体?
【问题讨论】:
-
你试过这个吗?字体字体 = Typeface.createFromAsset(getAssets(), "robotobold.ttf"); myButton.setTypeface(字体);
-
谢谢,但是您阅读了这个问题吗? ;-) 正如我在问题的第一个示例中所描述的那样,当直接使用按钮时,您所写的内容非常有效。但是,在使用小部件时,我无法直接访问视图,只能通过
RemoteViews....
标签: android widget android-remoteview