我彻底搜索了 SO 但没有得到我的问题的答案。
我想设置一个段落,我将使用 XML 设置它
文本包含标题和步骤以及常规文本。我想将标题和步骤设为粗体,其余部分设为普通文本。
我可以通过使用不同的 来做到这一点,但我如何才能在同一个 TextView 中做到这一点。
我的意思是使用相同的TextView如何为不同的句子设置不同的属性?
最佳答案
使用可生成的字符串
TextView tv = (TextView) findViewById(R.id.tv);
String steps = "Hello Everyone";
String title="Bold Please!";
SpannableString ss1= new SpannableString(title);
ss1.setSpan(new StyleSpan(Typeface.BOLD), 0, ss1.length(), 0);
tv.append(ss1);
tv.append("\n");
tv.append(steps);
有关更多样式,请查看链接 @ http://blog.stylingandroid.com/archives/177
关于粗体和普通文本的 Android TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16961796/