Simeon Mark Fernandes
Simeon Mark Fernandes

Reputation: 107

How to add custom font to the action bar?

I wanted to know how to add my own custom font to the app name that appears in the action bar in android studio.

Upvotes: 0

Views: 326

Answers (2)

Ashish Agrawal
Ashish Agrawal

Reputation: 1977

You can set CustomLayout in ActionBar

this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);

LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.titleview, null);

//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.title)).setText(this.getTitle());

//assign the view to the actionbar
this.getActionBar().setCustomView(v);

You can assign the custom font to textview by using setTypeFace()

Upvotes: 1

kris larson
kris larson

Reputation: 30985

I did this by just making an image of the app name with the custom font then displaying the image as the logo in the action bar. Much simpler.

actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(R.drawable.app_logo);

Upvotes: 0

Related Questions