Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar title textsize decreases on orientation change

The Toolbar title textsize gets decreased when I change orientation from portrait to landscape and gets reset when I change back to portrait. The activity in which this happens extends ActionBarActivity which uses getSupportActionBar().

like image 845
isudansh Avatar asked Mar 16 '15 08:03

isudansh


2 Answers

Use the below solution:

<android.support.v7.widget.Toolbar
        android:id="@+id/main_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:titleTextAppearance="@style/ToolbarTitle"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

Toolbar Style:

<style name="ToolbarTitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
        <item name="android:textSize">20sp</item>
</style>
like image 139
Smeet Avatar answered Nov 27 '22 12:11

Smeet


I think this problem exists in android.support.v7.widget.Toolbar. Even I faced the same issue. But to maintain text size consistency I used the following method.

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

And use this style for toolbar.

<android.support.v7.widget.Toolbar 

    ....
    app:titleTextAppearance="@style/ToolbarText" />
like image 26
Pooja Avatar answered Nov 27 '22 13:11

Pooja