Android:如何以编程方式检查TextView是粗体还是斜体

Spe*_*123 4 android textview

我想知道如何构造一个if语句来检查TextView是粗体还是斜体.请帮忙.谢谢.

Bor*_*lov 10

http://developer.android.com/reference/android/widget/TextView.html#getTypeface()

public Typeface getTypeface ()
Run Code Online (Sandbox Code Playgroud)

收益:

当前显示文本的字体和样式.

if(yourTextViewInstance.getTypeface()!=null){
   if(yourTextViewInstance.getTypeface().getStyle()==Typeface.BOLD || yourTextViewInstance.getTypeface().getStyle()==Typeface.ITALIC){
      //do your stuff
   }
}
Run Code Online (Sandbox Code Playgroud)

  • 由于API级别1,`Typeface`还有`isBold()`和`isItalic()`方法. (7认同)