【问题标题】:setTextSize(float) not supported in remote TextView?远程 TextView 不支持 setTextSize(float)?
【发布时间】:2013-03-07 17:14:36
【问题描述】:

我正在尝试在 Widget 中设置远程 TextView 的文本大小,如下所示:

RemoteViews rv = new RemoteViews(mContext.getPackageName(), layoutId);
rv.setFloat(R.id.subject, "setTextSize", 10f);

虽然我可以设置文本颜色等其他属性或更改视图的可见性,但在使用 setTextSize 时,膨胀失败并显示以下错误消息(无堆栈跟踪):

Error inflating RemoteViews at position: 1, using loading view instead
android.widget.RemoteViews$ActionException:
view: android.widget.TextView doesn't have method: setTextSize (float)

setTextSize(float) 有 @RemotableViewMethod 注释,所以它应该被支持,但甚至找不到方法(“没有方法”和“不支持”错误之间存在差异)。

为什么明明有方法却找不到呢? 在 API 16 中为 RemoteViews 引入 setTextViewTextSize() 方法可能表明我的方法有问题? 任何帮助将不胜感激。

【问题讨论】:

    标签: android android-widget


    【解决方案1】:

    您应该在第三个参数中使用 int 类型。因此,删除使其成为显式浮点数的“f”。

    rv.setFloat(R.id.subject, "setTextSize", 10);
    

    【讨论】:

    • 这确实有效,即使我不知道为什么会这样!我想您必须深入研究 AOSP 源代码才能找到 float 不起作用而 int 起作用的原因。还是谢谢你!
    猜你喜欢
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 2020-07-28
    • 2018-03-06
    • 2020-02-12
    • 2017-09-22
    相关资源
    最近更新 更多