简体   繁体   中英

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM