2010-12-10 38 views
1

大きなEditTextボックスがあります。複数の行にヒントがあるEditText

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

私はのstrings.xmlに、以下でEditTextandroid:hint="@string/hints"を使用してみましたが、ヒントは、単一の行にまだあった:私は、ボックス内のヒントは、この(構文ハイライトは意図していない)に見えるようにしたいです。

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

EditTextでは、どのように複数行のヒントを得ることができますか?

+0

解決策が見つかりましたhttp://stackoverflow.com/questions/28060772/set-multi-line-for-edittexts-hint/34773607#34773607 – josuadas

答えて

11

あなたはそれらを明示的に指定することで、文字列内の改行を含めることができます。XMLで

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

改行がスペースとして扱われます。

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); 
関連する問題