Home » Android » android – Set Edittexts hint text style as italic

android – Set Edittexts hint text style as italic

Posted by: admin April 23, 2020 Leave a comment

Questions:

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?

How to&Answers:

Inside strings.xml

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

In your .xml file

  <EditText android:hint="@string/hint1" />

Answer:

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);
}

Answer:

Try out as below:

edittext.setHint(Html.fromHtml("<small><i>" + "Text Hint Here" + "</i></small>"));

Answer:

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"/>