I have an AppCompatEditText
Inside TextInputLayout
and set a hint from string resource.
<string name="company_name">Companyname <font fgcolor='#FF0000'>*</font></string>
The color of the star is not changing to red.
This is what What I got.
What I want (edited in photoshop)
I tried drawableEnd with an image, but the AppCompatEditText has the width as “match_parent”. So its displayed at the end. I don’t what that way. Is there any way to do it.
UPDATE :
Tried this:
company_name.setHint(Html.fromHtml("<small><i>" + "Text Hint Here" + "</i><font color=#FF0000>*</font></small>"));
This is what I got. The old hint is not replaced by new one. Both hints are showing.
5
Answers
Yes it is possible to change the hint color of TextInputLayout. Like this
Create textinputlayout file in styles folder
Set To Main Theme of App,It Works Only Highlight State Only
Note: This solution is not supported in api 16 or below. For that you are require to do this:
To change bottom line color, you can use this in your app theme:
To change floating label color
and use it like:
Hope this helps.
Try using the library named Spanny. With the help of this, we can include and can customize each and every character with different, color, font size, font style and many more things. And it can be used to set the hint as well as setting the text.
This is the link to the library Spanny
you can set that Spanny object by this:
or this:
Hope it helps.
To some extent possible …
here are my findings
Html/Spannable
onFloating
text ofTextInputEditText
is not working.txt_usemail.setHint(Html.fromHtml("<font color="#707E90">" + "Companyname" + "</font>" + "<font color="#FF0000">" + "*" + "</font>"));
Html/Spannable
onTextInputLayout
hint is not working.txt_usemail.setHint(Html.fromHtml("<font color="#707E90">" + "Companyname" + "</font>" + "<font color="#FF0000">" + "*" + "</font>"));
Html/Spannable
onTextInputEditText
is working.et_usemaill.setHint(Html.fromHtml("<font color="#707E90">" + "Companyname" + "</font>" + "<font color="#FF0000">" + "*" + "</font>"));
Now, problem here is if you
setHint()
onTextInputEditText
(like point 3) thenFloating
text won’t work.to use
Floating
text, we need tosetHint()
onTextInputLayout
Here is the trick using
EditText
focus/defocusstyle
layout
Result –
Just set hint for the
—
<com.google.android.material.textfield.TextInputLayout>
that contains
——
<EditText>
in your code
Code (Kotlin):
Layout: