Android的占位符文本添加到的EditText符文、Android、EditText

2023-09-12 10:50:33 作者:少年多沧桑

我如何添加一个占位符文字的EditText 中,是不是在XML中的类?

我在code以下的EditText 将在alertdialog显示出来:

 最后的EditText名=新的EditText(本);
 

解决方案

嗯,好吧。你要找的是什么 setHint(INT)。简单地传递从XML字符串的资源ID,你是好去。

修改

和XML格式,它只是安卓提示=someText

教程 金山WPS中文本占位符的特点与使用

How can I add a placeholder text to EditText in the class that isn't in the XML?

I have the following EditText in my code which will be shown in alertdialog:

    final EditText name = new EditText(this);

解决方案

Ah, ok. What you're looking for is setHint(int). Simply pass in a resource id of a string from your xml and you're good to go.

EDIT

And in XML, it's simply android:hint="someText"