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?
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.
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With