Article
How to change the Toolbar font on Android
May 10, 2018
A quick search on our beloved-yet-fickle Stack Overflow yields a handful of strategies for changing the font of the Toolbar. Top solutions include defining a custom Toolbar layout , setting text appearance at runtime , or worst of all, iterating through every Toolbar view .
What gives? I just want to change the font!Step 0: Add the support library. Set minSdk to 16+.
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
Step 1: Make a folder. Add a font to it.
Create a new directory, res/font
. Add a .ttf
file for the font you want to use. ( Google Fonts is a sweet place to browse)
Step 2: Define a Toolbar theme.
<!-- styles.xml -->
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:fontFamily">@font/pacifico</item>
</style>
Step 3: Add a toolbar to your layout. Give it your new theme.
<!-- Use android:theme NOT style -->
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ToolbarTheme"/>
Step 4: Set Toolbar in your Activity.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
Step 5: Enjoy
Andrew builds apps at Livefront .-
Andrew Haisting
Software Engineer