0

粗體字母比方說,我有這樣的:顯示字符串與對話消息

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) 
    .setMessage("I want THIS word to be bold and the rest normal!") 
    .create().show(); 

有什麼辦法讓Android的應用格式或加粗字體的文本字符串的部分?

+0

看看[SpannableString(https://developer.android.com/reference/android/text/SpannableString.html) – pathfinderelite

+0

發現涉及的Html不同的解決方案.fromHtml()這似乎很好 – KaliMa

回答

1

您可以將字符串添加到您的strings.xml像這樣:

<string name="bold_message">I want <b>THIS</b> word to be bold and the rest normal!</string> 

,然後在警告對話框中只使用setMessage(R.string.bold_message)

-2

您必須使用自定義對話框。默認的Android對話框沒有任何選項來執行此操作。
欲瞭解更多信息請參閱: Custom Dialog Android

0

使用Spannable串是簡單的方法

在你的string.xml中添加

<string name = "bold_message"><![CDATA[<p>This want <b>THIS</b> word to bold and the rest normal!</p>]]></string> 

在你的警告對話框

.setMessage(Html.fromHtml(R.string.bold_message);