开发者

How can I set an EditText to have italic hint text?

开发者 https://www.devze.com 2023-01-11 10:20 出处:网络
How can I set the hint text of an EditText to be italic in Androi开发者_JAVA技巧d?EditText.setText(\"\");

How can I set the hint text of an EditText to be italic in Androi开发者_JAVA技巧d?


EditText.setText("");
EditText.setHint("hint");
EditText.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
....
EditText.setText("text");
EditText.setTypeface(Typeface.MONOSPACE, Typeface.NORMAL);


To set text as italic, you can do the following:

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

If you would like the italic text to be a hint - when the EditText is empty for example - you must implement a method to check the text length, and when it is equal to zero, apply the above code.


You can do everything in XML.

First declare your hint in the "strings.xml" file. Your define it to be italic by using the "< i >" tag

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

Finally, in the layout declaration you add your hint referencing this previously declared string.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号