How can I set EditText to italic text?

How can I set the tooltip text in EditText, which will be italic in Android?

+3
source share
3 answers
EditText.setText("");
EditText.setHint("hint");
EditText.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
....
EditText.setText("text");
EditText.setTypeface(Typeface.MONOSPACE, Typeface.NORMAL);
+1
source

To set the text in italics, you can do the following:

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

If you want italic text to be a hint - when EditText is empty, for example, you should implement a method for checking the length of the text, and when it is zero, apply the above code.

0
source

You can do everything in XML.

First declare a hint in the file "strings.xml". You define it as italics using the "<i>" tag

<string name="EditBoxHint"><i>Whatever you want to show</i></string>

Finally, a tooltip is added to the layout declaration that references the previously declared line.

<EditText
    ...
    android:hint="@string/EditBoxHint"
    ...
/>
0
source

Source: https://habr.com/ru/post/1759274/


All Articles