Toolbar title textsize decreases on orientation change

﹥>﹥吖頭↗ 提交于 2019-12-10 14:44:54

问题


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().


回答1:


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>



回答2:


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


来源:https://stackoverflow.com/questions/29072345/toolbar-title-textsize-decreases-on-orientation-change

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