Search code examples
androidandroid-toolbarportrait

Android Lollipop toolbar `setTitle`


<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/purple"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

When I use the setTitle() method, it all works fine. But the problem is that when I change orientation (since in lollipop 5.1 I can do so) the title word is small compared to portrait version. Why such bug? and how do I solve this?


Solution

  • By default the Toolbar's fontsize is smaller in landscape.

    If you want it to have the same size as in portrait you can set a custom titleTextAppearance:

    <android.support.v7.widget.Toolbar
        app:titleTextAppearance="@style/YourToolbarTitleStyle"
        .../>
    

    with YourToolbarTitleStyle being defined as a style where you specify a text size:

    <style name="YourToolbarTitleStyle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
        <item name="android:textSize">20sp</item>
    </style>