How to customize the caption font of the action bar?

I created an ActionBar ( android.support.v7.widget.Toolbar ) as shown below.

 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myToolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize"> </android.support.v7.widget.Toolbar> 

In my ActionBar, besides the name, I also have a Subtitle. However, I would like to configure Subtitle. In setup, I mean font size, color, and font.

I tried various themes and styles and still have not been successful.

If there is a simple complete example of how this could be done, it would really help. Thanks!

+5
source share
1 answer

If you do not already have this namespace attribute in your layout file, add it:

XMLNS: application = "http://schemas.android.com/apk/res-auto"

Update the toolbar attributes in the layout file as follows:

 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myToolbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:titleTextAppearance="@style/ToolbarTitleAppearance" app:subtitleTextAppearance="@style/ToolbarSubtitleAppearance" android:minHeight="?attr/actionBarSize"> </android.support.v7.widget.Toolbar> 

Add styles like these:

 <style name="ToolbarTitleAppearance" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"> <item name="android:textSize">20dp</item> <!-- include other attributes you want to change: textColor, textStyle, etc --> </style> <style name="ToolbarSubtitleAppearance" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle"> <item name="android:textSize">14dp</item> </style> 
+32
source

All Articles