Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.4k points)

Is there a way to set the textStyle attribute of a TextView programmatically? There doesn't appear to be a setTextStyle() method.

To be clear, I am not talking about View / Widget styles! I am talking about the following:

<TextView

  android:id="@+id/my_text"

  android:layout_width="fill_parent"

  android:layout_height="wrap_content"

  android:text="Hello World"

  android:textStyle="bold" />

1 Answer

0 votes
by (46k points)

textview.setTypeface(Typeface.DEFAULT_BOLD);

setTypeface is the Attribute textStyle.

 to save the last set typeface attributes you can use:

textview.setTypeface(textview.getTypeface(), Typeface.BOLD);

Related questions

0 votes
1 answer
asked Sep 9, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...