I'm trying to utilize TextInput Layout for Floating Labels available in android material design, where i'm showing error using app:errorTextAppearance flag. For this errorTextAppearance I'm unable to apply custom font.
I can change color and other things but not able to apply custom font.
I'm trying match font style of "Please select question" with "Please enter answer" P.S "Please select question" was a plain text view and i was able to change font easily.
I can't post image but below link has it.
Input Text Layout
Could you please help me with this issue.
As mentioned here:
You can use a SpannableString to set the font:
SpannableString s = new SpannableString(errorString);
s.setSpan(new TypefaceSpan(font), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mPasswordView.setError(s);
A custom Span class that has a specific Typeface set:
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With