我正在使用以下代码将字体大小更改为中、高或小。 getFontSize()
将返回这些大小中的任何一个
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
holder.title.setTextAppearance(new AppController().getFontSize());
else
holder.title.setTextAppearance(mContext, new AppController().getFontSize());
但是我收到以下错误:
java.lang.NoSuchMethodError: No virtual method setTextAppearance(I)V in class Landroid/widget/TextView; or its super classes (declaration of 'android.widget.TextView' appears in /system/framework/framework.jar)
为什么会出现这样的错误?
最佳答案
TextView::setTextAppearance
需要一个整数值,用于标识项目中的样式资源(如 @android:style/TextAppearance.Material.Body1
)。
如果这是您的 Intent ,请确保您的 getFontSize() 方法返回有效 ID。
但是,我想,您实际上是在尝试设置字体大小,这应该使用 TextView 的 setTextSize(float size)
方法来完成。
关于android - 设置文本外观时没有此类方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41567431/