Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a custom font to the title in toolbar android

I am doing this:

toolbar = (Toolbar) findViewById(com.sports.unity.R.id.tool_bar); setSupportActionBar(toolbar); setTitle("hello"); 

I want to set a custom font for the text here in the title "hello". How to do that?

like image 752
anupam x Avatar asked Sep 04 '15 12:09

anupam x


People also ask

How can I change the font of title bar in Android?

In method 1 Just go to the activity_main. xml file and add a TextView in the toolbar widget with the font-family attribute. The complete code for the activity_main. xml file is given below.

How do I add fonts to my toolbar?

Then, go to the design tab of your XML file, and select the text on the toolbar. Select the option of fontFamily and select the font you want under the given options. If it is not given, you can search for more fonts. Search for the font you want and select it.

How do I change the font on my app title?

To change the font, go to Settings–>Display–>Font size and style. Tap the font's name that you want and set it as the system font.


1 Answers

Since android.support.v7.appcompat 24.2 Toolbar has method setTitleTextAppearance and you can set its font without external textview.

create new style in styles.xml

<style name="RobotoBoldTextAppearance">         <item name="android:fontFamily">@font/roboto_condensed_bold</item> </style> 

and use it

mToolbar.setTitleTextAppearance(this, R.style.RobotoBoldTextAppearance); 
like image 188
Rainmaker Avatar answered Oct 10 '22 21:10

Rainmaker