How to customize the Action Bar subtitle Font?

一世执手 提交于 2019-12-02 23:16:42

If you don't already have this namespace attribute in your layout file add it:

xmlns:app="http://schemas.android.com/apk/res-auto"

Update your Toolbar attributes in your layout file like this:

<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>

Comments on this answer discuss whether the units for textSize should be dp or sp. When I originally wrote this answer, I looked at the Android source files and saw that dp was used. I recommend staying with that. As FrancescoDonzello explains in his comment, the size of the Toolbar is fixed and, unlike other widgets, will not expand to contain text enlarged by changes to the phone settings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!