2
EditTextのTextInputLayoutエラーテキストフォントを変更することはできますか?TextInputLayoutのエラーフォントを変更しますか?
app:errorTextAppearanceを使用して、色またはテキストサイズを変更することしかできませんでした。
あなたは、フォント設定するSpannableString
を使用することができます
EditTextのTextInputLayoutエラーテキストフォントを変更することはできますか?TextInputLayoutのエラーフォントを変更しますか?
app:errorTextAppearanceを使用して、色またはテキストサイズを変更することしかできませんでした。
あなたは、フォント設定するSpannableString
を使用することができます
:
public class TypefaceSpan extends MetricAffectingSpan {
private Typeface mTypeface;
public TypefaceSpan(Typeface typeface) {
mTypeface = typeface;
}
@Override
public void updateMeasureState(TextPaint p) {
p.setTypeface(mTypeface);
p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setTypeface(mTypeface);
tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
}
別の方法あなたがそれを好きならば、あなたはを設定することができます。特定のTypeface
セットを持ってい
SpannableString s = new SpannableString(errorString);
s.setSpan(new TypefaceSpan(font), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mPasswordView.setError(s);
カスタムSpan
クラスをエラーの色またはフォント両方
public static void setErrorTextColor(TextInputLayout textInputLayout, int color, Typeface font) {
try {
Field fErrorView = TextInputLayout.class.getDeclaredField("mErrorView");
fErrorView.setAccessible(true);
TextView mErrorView = (TextView) fErrorView.get(textInputLayout);
Field fCurTextColor = TextView.class.getDeclaredField("mCurTextColor");
fCurTextColor.setAccessible(true);
fCurTextColor.set(mErrorView, color);
mErrorView.setTypeface(font);
} catch (Exception e) {
e.printStackTrace();
}
}
あなたは何を完全に試してみたかを示してください。それで解決策を見つけるのは簡単でしょう。 – Androider