1

I have a textInputLayout with a TextInputEditText.

I would like the hint text to be in Roboto and the edit field (the text that user is entering) to be of a custom font, but can't seem to get it working. Somehow if I try to set a font on the TextInputEditText it also affects the hint text's font.

Anyone know how to get this issue solved?

*** edit: Found some weird thing. When I set the inputType to textPassword on the TextInputeditText (and have my custom font set on same widget via fontFamily=".." then I do have two different fonts on hint and edit field?!! But unfortunately for any other input type and in my case I need inputType="textEmailAddress" the hint text changes to same font as TextInputEditText

Rik van Velzen
  • 1,977
  • 1
  • 19
  • 37

2 Answers2

1

I found the solution: You need to set typeFace on the TextInputLayout programmatically for the font you want for the hint text. The font for the TextInputEditText fields can be set directly in either xml or programatically.

Rik van Velzen
  • 1,977
  • 1
  • 19
  • 37
0

Default EditText does not offer a method to set the Typeface of the hint only, but if you set a custom typeface to your EditText, all the text fields are affected.

To obtain what you want, you need to define a custom TypefaceSpan and a SpannableString, as suggested in this topic.

Please have a look at francisco_ssb answer.

dalla92
  • 432
  • 2
  • 8
  • this solution looked interesting, it just doesn't seem to be working as desired. When I set hint programmatically, as opposed to by xml, now the hint text functionality is working differently(.... ?). The hint text font changes indeed, but now the hint text doesn't animate to above the edit field when it gets focus. It just disappears. – Rik van Velzen Dec 14 '17 at 10:55
  • If this solution didn't fit your needs, have you tried to set the custom font on the TextInputLayout, instead of on the TextInputEditText? In this way you should be able to customize just the hint font. – dalla92 Dec 14 '17 at 11:32
  • Yes, I have tried setting the spannable string to both the textInputLayout as well as the TextInputEditText. And also tried setting fontFamily in xml to both widgets but to no avail. (thanks for your input btw.!) – Rik van Velzen Dec 14 '17 at 11:49
  • Maybe this post can help you: https://stackoverflow.com/questions/43135775/how-to-change-the-font-of-the-edittext-hint-in-android – dalla92 Dec 14 '17 at 13:18