Android: how to check if TextView is bold or italic

I would like to know how to build an if statement to check if the TextView is in bold or italics. Please help. Thanks.

+4
source share
3 answers

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

public Typeface getTypeface () 

returns:

the current font and style in which the text is displayed.

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

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

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

}

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

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

Try

 textView.getTypeface() 

then check if it is equal

  • Typeface.BOLD
  • Typeface.ITALIC
  • Typeface.BOLD_ITALIC
0
source

Source: https://habr.com/ru/post/1494917/


All Articles