Akeshwar Jha
Akeshwar Jha

Reputation: 4576

How to change fontFamily of a button text through layout XML file in android?

The title pretty much describes my question. I want to change the font of the text written on my button using XML files. Is it possible? For a simple TextView, this works:

android:fontFamily="sans-serif"

But for buttons, how can we do it by using only the layout xml files?

Upvotes: 1

Views: 5385

Answers (2)

Harsh Sharma
Harsh Sharma

Reputation: 898

Android comes with 3 fonts (Sans, Serif, Monospace) which can be accesed using android:typeface=”FONT_NAME”. For using your own fonts, read this article. May it will help.

Programmatically

Button n=(Button) findViewById(R.id.button1);
      Typeface typeface = Typeface.createFromAsset(getAssets(), "Helv Neue 67 Med Cond.ttf");
      n.setText("show");
      n.setTypeface(typeface);

Upvotes: 3

Kristo
Kristo

Reputation: 1367

Maybe you could use this:

android:typeface=”FONT_NAME”

Hope it helps.

Upvotes: 1

Related Questions