【问题标题】:How to change the font / typeface of a button in RemoteViews of an Android Widget?如何更改 Android 小部件 RemoteViews 中按钮的字体/字体?
【发布时间】: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


【解决方案1】:

RemoteViewTextView的字体无法更改。

要检查可以在 RemoteView 中更改的属性,在您的情况下,只需转到 ButtonTextView 类并检查所有带有注释的方法@android.view.RemotableViewMethod。可以看到,setTypeface没有注解,所以在RemoteView中无论如何也无法更改

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多