Skip to content Skip to sidebar Skip to footer

Android: How To Check If Textview Is Bold Or Italic Programatically

I would like to know how to construct an if statement to check if a TextView is bold or italic. Please help. Thank you.

Solution 1:

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

public Typeface getTypeface ()

returns:

the current typeface and style in which the text is being displayed.

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

Solution 2:

To check if textview is BOLD and ITALIC, use following code:

if((textView.getTypeface().getStyle() & Typeface.BOLD)!=0 &&(textView.getTypeface().getStyle() & Typeface.ITALIC)!=0){
                  //do your stuff

}

To check if textview is either BOLD or ITALIC, use following code:

if((textView.getTypeface().getStyle() & Typeface.BOLD)!=0 ||(textView.getTypeface().getStyle() & Typeface.ITALIC)!=0){
                      //do your stuff
}

Solution 3:

Try

textView.getTypeface()

then check if it is equal to

  • Typeface.BOLD
  • Typeface.ITALIC
  • Typeface.BOLD_ITALIC

Post a Comment for "Android: How To Check If Textview Is Bold Or Italic Programatically"