2

I have a large EditText box. I want a hint in the 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?

mndrix
  • 3,131
  • 1
  • 30
  • 23

2 Answers2

11

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.

Blrfl
  • 6,817
  • 1
  • 25
  • 25
  • I Tried same **\n** for Hint new line,it's work at design time i mean in XML ,but it didn't work in real device in real device its display single line.can explain what the issue ? – Arbaz.in Dec 14 '18 at 05:42
1

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 );
mndrix
  • 3,131
  • 1
  • 30
  • 23