How to programmatically configure a font for text viewing?

I am using textview in my application. In this, I have to programmatically change the font for the text text. In the button click function, I need to change the textview font. If the font is Normal, I need to convert to Bold (vice versa). If anyone knows the answer means kindly share with me. Thanks.

+4
source share
3 answers

To make your text visually bold programmatically:

textView.setTypeface(null, Typeface.BOLD); 

To return it to its normal state, follow these steps:

 textView.setTypeface(null, Typeface.NORMAL); 

To get the current font type, use getTypeface()

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

+29
source
  setTypeface(Typeface tf, int style) Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified. 

Android documentation

+1
source

try it

 TextView textview= (TextView) findViewById(R.id.appname) textView.setTypeface(null, Typeface.BOLD); textView.setTypeface(null, Typeface.ITALIC); textView.setTypeface(null, Typeface.BOLD_ITALIC); 
0
source

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


All Articles