How to change to property android:fontFamily="casual" in a textView dynamically?

Asked

Viewed 27 times

1

I would like to know how to change the font to casual in my textView through java code.

TextView text1 = findViewById(R.id.myTextView);

I want to change the font from text1 to casual (android:fontFamily="casual"), but I don’t know how to do it through java code. How to do this?

1 answer

0


It’s simple, do the following:

Typeface tf = Typeface.create("casual", Typeface.NORMAL);
text1.setTypeface(tf);

where text1 is yours TextView, "casual" is the font you want.

I hope I’ve helped.

  • Perfect friend I’ll give a try now....

  • It worked perfectly - Obs! I was wrong in typing the question.... I wrote it down android:famalyFont="casual" but the right thing is android:fontFamily="casual".... But since we’re on the subject then correct me if I’m wrong, but this property is for API16+ I’m right?

  • Both the Typeface.create(), how much textview.setTypeface(), are provided by API 1. according to Typeface and Textview

Browser other questions tagged

You are not signed in. Login or sign up in order to post.