带有多行提示的 EditText

发布于 2024-10-07 05:13:17 字数 473 浏览 1 评论 0原文

我有一个大的 EditText 框。我希望框中的提示看起来像这样(不是有意的语法突出显示):

Hint about the first line
Hint about the second line
Hint about the third line

我尝试在 EditText 上使用 android:hint="@string/hints" 以及在 strings.xml 中,但提示仍然在一行上。

<string name="hints">
Hint about the first line
Hint about the second line
Hint about the third line
</string>

如何在 EditText 中获取多行提示?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨轻弹 2024-10-14 05:13:17

您可以通过显式指定在字符串中包含换行符:

<string name="hint">Manny, Moe and Jack\nThey know what I\'m after.</string>

XML 中的换行符被视为空格。

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.

满身野味 2024-10-14 05:13:17

为每一行创建一个单独的字符串资源:

<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 );

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 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文