Android 设置文本外观时没有此类方法错误
我正在使用以下代码将字体大小更改为中、高或小Android 设置文本外观时没有此类方法错误,android,nosuchmethoderror,Android,Nosuchmethoderror,我正在使用以下代码将字体大小更改为中、高或小getFontSize()将返回这些大小中的任何一个 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.title.setTextAppearance(new AppController().getFontSize()); else holder.title.setTextAppearance(mContext, new AppController().g
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
)。
如果这是您的意图,那么请确保getFontSize()方法返回有效的ID
但是,我想,您实际上是在尝试设置字体大小,这应该使用TextView的
setTextSize(float size)
方法来完成。请看这里的问题,看起来编译器应该失败,但它没有失败,所以它会在live中崩溃。根据@rafsanahmad007链接,我认为它与@deprecated方法有关。你确定new-AppController().getFontSize()
返回@StyleRes int
(int
表示样式资源)?尝试跟随,但我正在chip.settext外观中设置样式(R.style.ChipTextStyle\u选中);@color/chip\u color\u选择器的样式在哪里?有更新吗?我也正在将样式设置为芯片,它在少数棒棒糖设备中崩溃了@安德烈极客