DAS
DAS

Reputation: 696

How to set the TextInputLayout hint with multiple styles?

I have a TextInputLayout and Edittext inside that, Need to make the hint with multiple styles like Date of Birth mm/dd/yyyy. The mm/dd/yyyy only should be italic and when we focus on the Edittext the same format text should be there on the top (as TextInputLayout working).

What I have tried, and the similar ones are out there:

  1. Using SpannableString and setting the hint on EditText
  2. Assigning the Htmlformatter and setting the hint on the editext

For both the above Issue -- when the focus is on the edittext the floating text not available.

  1. Setting Hint on the TextInputLayout using SpannableString and Htmlformatter: For this one Issue The italics for mm/dd/yyyy wont work, but the focus and floating text works.

Need to know how we can style TextInputLayout hint with multiple styles having the floating also with the same styled text.

Upvotes: 1

Views: 356

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363469

With the Material Components library, starting with 1.2.0-alpha05 you can format the hint text.

Just use:

    <com.google.android.material.textfield.TextInputLayout
        android:hint="@string/hint_italic"
        >

with:

<string name="hint_italic">Date of Birth <i>mm/dd/yyyy</i></string>

enter image description hereenter image description here

Upvotes: 0

Related Questions