How to change Action Bar/Title Bar font?
10,193
Solution 1
As some other users have suggested, you can use a toolbar, but if you don't want to or you have to keep using the action bar, then you can define the style of the action bar in your style like this:
<style name="baseStyle" parent="@style/Theme.MaterialComponents.Light.Bridge">
<item name="actionBarStyle">@style/myActionBarStyle</item>
...
</style>
and inside myActionBarStyle
define the font:
<style name="myActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="fontFamily">@font/customFont</item>
...
</style>
this will affect the font only in the action bar and not in the whole app
Solution 2
You can make a custom toolbar. below is code snapshot
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
and then you can access toolbar_title in your java class(Activity or Fragment) and set a custom font style.
Related videos on Youtube
Author by
nicoqueijo
Updated on June 04, 2022Comments
-
nicoqueijo almost 2 years
Not sure if this is called the action bar or the title bar but I need to change the font to a font I have in my assets folder. How do I do this?
-
nicoqueijo about 7 yearsHow do I access the toolbar variable? Doesn't exist in my activity when I start typing it.
-
John about 7 yearsDo you use toolbar or action bar
-
nicoqueijo about 7 yearsNot sure. It is the default when you create an empty activity. I'm not referencing it in my xml or java though.
-
nicoqueijo about 7 yearsThis adds another bar under the existing bar. I'm trying to edit the existing bar which comes as default when you create the project.
-
nicoqueijo about 7 yearsWhen I apply the code you gave me titleview_2 shows up as red (Cannot resolve symbol 'titleview_2')
-
John about 7 yearsOr try Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
-
Braj Bhushan Singh about 7 yearsGive your layout name as titleview_2.
-
Prasath about 4 yearsThe Question is about Custom fonts but you wrote about app bat title.