Android - set TextView TextStyle programmatically?

422    Asked by Aalapprabhakaran in Python , Asked on Jul 19, 2021

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:

  android:id="@+id/my_text"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Hello World"
  android:textStyle="bold" />

Answered by Aryan Khan

Use the below-mentioned code to resolve android textstyle:

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);

Your Answer

Interviews

Parent Categories