Android 类中没有字段mCollapsingTextHelper
您好,我想使用以下代码设置TextInputLayout字体:Android 类中没有字段mCollapsingTextHelper,android,kotlin,android-textinputlayout,typeface,Android,Kotlin,Android Textinputlayout,Typeface,您好,我想使用以下代码设置TextInputLayout字体: public class CustomFont { public static void setTypefaceToInputLayout(TextInputLayout inputLayout, String typeFace, Context context){ final Typeface tf = Typeface.createFromAsset(context.getAssets(), typeF
public class CustomFont {
public static void setTypefaceToInputLayout(TextInputLayout inputLayout, String typeFace, Context context){
final Typeface tf = Typeface.createFromAsset(context.getAssets(), typeFace);
inputLayout.getEditText().setTypeface(tf);
try {
// Retrieve the CollapsingTextHelper Field
final Field collapsingTextHelperField = inputLayout.getClass().getDeclaredField("mCollapsingTextHelper");
collapsingTextHelperField.setAccessible(true);
// Retrieve an instance of CollapsingTextHelper and its TextPaint
final Object collapsingTextHelper = collapsingTextHelperField.get(inputLayout);
final Field tpf = collapsingTextHelper.getClass().getDeclaredField("mTextPaint");
tpf.setAccessible(true);
// Apply your Typeface to the CollapsingTextHelper TextPaint
((TextPaint) tpf.get(collapsingTextHelper)).setTypeface(tf);
} catch (Exception ignored) {
// Nothing to do
Log.e("errorXYZ","error:::"+ignored.toString());
}
}
}
该方法是用Java编写的,我在Kotlin中将其调用为:
CustomFont.setTypefaceToInputLayout(externalView.passwordTIL,"fonts/af/dragon.ttf",context!!)
我从过去24小时就开始尝试,出于某种原因,我需要不惜一切代价设置TextInputLayout字体(实际上是浮动提示字体)
我一直收到以下异常:
java.lang.NoSuchFieldException: No field mCollapsingTextHelper in class Landroid/support/design/widget/TextInputLayout; (declaration of 'android.support.design.widget.TextInputLayout' appears in /data/app/com.ar.ere-2/base.apk:classes2.dex)
我不知道这个异常,但我在gradle文件中启用了mutlidex。那么我应该从Multidex库中排除一些文件吗?但是怎么做呢
我一点也不知道
有人能回顾一下情况吗 您正在使用反射来访问不存在的字段
有一种方法,可用于更改浮动提示和任何错误消息。您正在使用反射来访问不存在的字段
具有一个可用于更改浮动提示和任何错误消息的方法。
mCollapsingTextHelper
已重命名为collapsingTextHelper
可能是mTextPaint
已重命名为textPaint
请查收
已将
mCollapsingTextHelper
重命名为collapsingTextHelper
可能是mTextPaint
已重命名为textPaint
请查收
您将哪个库和版本用于
TextInputLayout
?您将哪个库和版本用于TextInputLayout
?