I need to change the default font of my application toolbar, I just switched to material design and it looks pretty new,
Am building an educational app for kids, so I need to change from the professional inbuilt toolbar font.
Asked
Active
Viewed 508 times
2

Peter Ola
- 132
- 8
-
1you can add TextView to the toolbar and set the font type to it, the toolbar is just like any Layout it can have childs – Kosh Nov 01 '15 at 07:42
2 Answers
5
There are couple of options to do that:
Create a custom TypeFace class and use SpannableString to set the ActionBar Title like this.
SpannableString s = new SpannableString("My Title");
s.setSpan(new TypefaceSpan(this, "MyTypeface.otf"), 0, s.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Update the action bar title with the TypefaceSpan instance
ActionBar actionBar = getActionBar();
actionBar.setTitle(s);
See this link to get the solution
or
add a TextView
inside the Toolbar
and set its attributes
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="My custom Text"
android:textColor="#fff"/>
</android.support.v7.widget.Toolbar>

Community
- 1
- 1

Pavitra Kansara
- 819
- 8
- 14
0
Try this:
SpannableString title = new SpannableString(param);
title.setSpan(new TypefaceSpan(context,"Roboto-Regular.ttf"),0,title.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//If doing in fragment then
((AppCompatActivity)getActivity()).getSupportActionBar().setTitle(title)
//otherwise in activity
getSupportActionBar().setTitle(title)
Make sure that you have set Toolbar as action bar, to do that:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
If you haven't set toolbar as action bar then once you prepare Spannable String instead of getSupportActionBar().setTitle(title) use toolbar object to set title
toolbar.setTitle(title)

yashodhan divakaran
- 271
- 2
- 14