27 个答案:
答案 0 :(得分:1732)
textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
textView.setTypeface(null, Typeface.NORMAL);
保留以前的字体
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC)
答案 1 :(得分:258)
尝试将TextView设置为粗体或斜体
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
textView.setTypeface(textView.getTypeface(), Typeface.ITALIC);
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC);
答案 2 :(得分:128)
编程:
您可以使用setTypeface()编程:
textView.setTypeface(null, Typeface.NORMAL); // for Normal Text
textView.setTypeface(null, Typeface.BOLD); // for Bold only
textView.setTypeface(null, Typeface.ITALIC); // for Italic
textView.setTypeface(null, Typeface.BOLD_ITALIC); // for Bold and Italic
XML:
您可以在中直接在XML文件中设置:
android:textStyle="normal"
android:textStyle="normal|bold"
android:textStyle="normal|italic"
android:textStyle="bold"
android:textStyle="bold|italic"
答案 3 :(得分:86)
您有两种选择:
选项1(仅适用于粗体,斜体和下划线):
String s = "Bolded text, italic text, even underlined!"
TextView tv = (TextView)findViewById(R.id.THE_TEXTVIEW_ID);
tv.setText(Html.fromHtml(s));
选项2:
使用Spannable;它更复杂,但您可以动态修改文本属性(不仅是粗体/斜体,还有颜色)。
答案 4 :(得分:35)
编程:
您可以使用setTypeface()方法以编程方式执行:
以下是默认字体的代码
textView