我有一个很大的EditText
框。我希望框中的提示看起来像这样(语法高亮不是意图):
Hint about the first line
Hint about the second line
Hint about the third line
我尝试在android:hint="@string/hints"
上使用EditText
,并在strings.xml中使用以下内容,但提示仍在一行中。
<string name="hints">
Hint about the first line
Hint about the second line
Hint about the third line
</string>
如何在EditText
中获得多行提示?
答案 0 :(得分:11)
您可以通过明确指定字符串在字符串中包含换行符:
<string name="hint">Manny, Moe and Jack\nThey know what I\'m after.</string>
XML中的换行符被视为空格。
答案 1 :(得分:1)
为每一行创建一个单独的字符串资源:
<string name="hint_one">Hint about the first line</string>
<string name="hint_two">Hint about the second line</string>
<string name="hint_three">Hint about the third line</string>
在布局XML中不包含android:hint
属性。在创建EditText
的位置,手动设置提示:
// get the string values
final Resources res = getResources();
final String one = res.getString(R.string.hint_one);
final String two = res.getString(R.string.hint_two);
final String three = res.getString(R.string.hint_three);
// set the hint
final EditText et = (EditText) findViewById(R.id.some_edit_text);
et.setHint( one + "\n" + two + "\n" + three );