Warm tip: This article is reproduced from serverfault.com, please click

android-在对话框消息中显示带有粗体字母的字符串

(android - Display string with bold letters in Dialog message)

发布于 2016-11-04 19:06:09

假设我有这个:

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

有什么办法让Android将格式设置或粗体字体应用于部分文本字符串?

Questioner
KaliMa
Viewed
11
Pedro Cardoso 2016-11-05 03:14:21

你可以像这样在你的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)