Set Edittexts hint text style as italic
Asked Answered
A

3

35

I need to set the hint of a EditText as italic style, but I can't find any place how to do it.

Some one here has a clue how to do it or do I have to accept that is impossible?

Acetone answered 4/2, 2013 at 10:14 Comment(1)
Was a duplicate of: https://mcmap.net/q/428551/-how-can-i-set-an-edittext-to-have-italic-hint-textPortaltoportal
N
90

Inside strings.xml

 <string name="hint1"><i>Your hint here</i></string>

In your .xml file

  <EditText android:hint="@string/hint1" />
Nighttime answered 4/2, 2013 at 10:24 Comment(4)
Thank you. Quite easy. Didn't know that I could use tags inside a tag.Acetone
For the record, I just tried <em></em> and it did not work.Synodic
@LiterateCorvette - what is em?Nighttime
@Nighttime emphasis instead of italics, generally the same as <i> to the user, but it is now the preferred tag in most use cases. Here's an explanation.Synodic
P
21

Add one string value in Strings.xml as <i>your hint here</i> and try to set it in your EditText in the xml

Solution 2:

if(youredittext.getText().toString().length()==0)
{
    youredittext.setTypeface(null,Typeface.ITALIC);
}
else
{
youredittext.setTypeface(null,Typeface.NORMAL);
}
Prouty answered 4/2, 2013 at 10:21 Comment(1)
Your first solution with setting <i>hint</i>works very well and look good in the xml.Acetone
P
0

In your xml, you can set a TextStyle. This TextStyle is applicable on your text and your hint.

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@Your text here"
android:textStyle="italic"/>
Physician answered 5/1, 2015 at 12:48 Comment(1)
TextStyle impacts the entered text, OP wants to set the style of hint text only.Septuple

© 2022 - 2024 — McMap. All rights reserved.