设置TextView样式(粗体或斜体)

如何在Java中设置TextView样式(粗体或斜体)而不使用XML布局?

换句话说,我需要用Java编写android:textStyle


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)

试试这个设置为粗体或斜体的TextView

textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
textView.setTypeface(textView.getTypeface(), Typeface.ITALIC);
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC);

编程方式:

你可以使用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:

您可以在<TextView />直接在XML文件中设置,如:

android:textStyle="normal"
android:textStyle="normal|bold"
android:textStyle="normal|italic"
android:textStyle="bold"
android:textStyle="bold|italic"
链接地址: http://www.djcxy.com/p/36585.html

上一篇: Set TextView style (bold or italic)

下一篇: Auto Scale TextView Text to Fit within Bounds