简体   繁体   English

Android Lollipop工具栏`setTitle`

[英]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. 当我使用setTitle()方法时,一切正常。 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. 但是问题是,当我改变方向时(因为在棒棒糖5.1中可以这样做),与纵向版本相比,标题词很小。 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 : 如果您希望它的大小与纵向相同,则可以设置自定义titleTextAppearance

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

with YourToolbarTitleStyle being defined as a style where you specify a text size: YourToolbarTitleStyle定义为一种样式,您可以在其中指定文本大小:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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