I have a large EditText
box. I want a hint in th开发者_运维问答e box to look like this (syntax highlight not intended):
Hint about the first line
Hint about the second line
Hint about the third line
I tried using android:hint="@string/hints"
on the EditText
with the following in strings.xml, but the hint was still on a single line.
<string name="hints">
Hint about the first line
Hint about the second line
Hint about the third line
</string>
How can one obtain a multiline hint in an EditText
?
You can include newlines in strings by explicitly specifying them:
<string name="hint">Manny, Moe and Jack\nThey know what I\'m after.</string>
Newlines in the XML are treated as spaces.
Make a separate string resource for each line:
<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>
don't include an android:hint
attribute in your layout XML. Where the EditText
is created, set the hint manually:
// 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 );
精彩评论