Android工具栏:横向模式下的小标题文本

宁陈永利

我正在测试Android上的新工具栏和AppCompat主题,但遇到了问题。我的工具栏标题文本在纵向模式下看起来是正常大小,但在横向模式下却变得很小,尽管我在代码中未做任何更改标题文本大小的操作。以下是屏幕截图:

肖像 风景

activity_main.xml:

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.techfunmyanmar.jujaka.ui.MainActivity">

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

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- As the main content view, the view below consumes the entire
             space available using match_parent in both dimensions. -->
        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- android:layout_gravity="start" tells DrawerLayout to treat
             this as a sliding drawer on the left side for left-to-right
             languages and on the right side for right-to-left languages.
             If you're not building against API 17 or higher, use
             android:layout_gravity="left" instead. -->
        <!-- The drawer is given a fixed width in dp and extends the full height of
             the container. -->
        <fragment
            android:id="@+id/navigation_drawer"
            android:name="com.techfunmyanmar.jujaka.ui.NavigationDrawerFragment"
            android:layout_width="@dimen/navigation_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            tools:layout="@layout/fragment_navigation_drawer" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

styles.xml:

<resources>
    <!-- Base application theme. -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>

        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>

    </style>

    <!-- Main application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">

    </style>

    <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
        <item name="spinBars">true</item>
    </style>
</resources>
宁陈永利

我尝试设置android:titleTextAppearance工具栏,但未应用样式。然后我意识到我正在使用AppCompat主题,所以我使用app:titleTextAppearance了该样式,现在正在应用该样式。看起来横向中的小字母是内置AppCompat.Toolbar.Title样式本身的问题,因此我覆盖了它以手动设置字体大小。最终代码:

工具栏XML:

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

工具栏样式:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android:如何使文本与标题文本工具栏左对齐?

来自分类Dev

使用Espresso测试工具栏标题文本-Android

来自分类Dev

如何在横向模式下制作垂直工具栏,在纵向模式下旋转变为水平?

来自分类Dev

在标题栏工具栏android中添加菜单项文本和文本

来自分类Dev

Android多行工具栏标题

来自分类Dev

在android中更改工具栏标题

来自分类Dev

Android中工具栏标题中的多行标题

来自分类Dev

android标题受其他标题影响(工具栏)

来自分类Dev

Android中工具栏标题中的多行标题

来自分类Dev

如何仅在某些模式下显示工具栏?

来自分类Dev

如何仅在某些模式下显示工具栏?

来自分类Dev

设置工具栏标题

来自分类Dev

在工具栏/操作栏中更改文本颜色,Android?

来自分类Dev

标题等未显示在Android工具栏中

来自分类Dev

Android:何时设置工具栏标题表单片段?

来自分类Dev

从Android中的片段在工具栏中设置标题

来自分类Dev

Android Lollipop,从工具栏中的标题添加弹出菜单

来自分类Dev

android标题不会显示在工具栏中

来自分类Dev

Android-将工具栏的标题居中

来自分类Dev

Android:何时设置工具栏标题形式的Fragment?

来自分类Dev

Android-工具栏标题的重力不正确

来自分类Dev

Android BottomSheet:隐藏在工具栏下

来自分类Dev

Android工具栏的文本大小和样式

来自分类Dev

Android自定义工具栏文本按钮

来自分类Dev

如何与工具栏的标题对齐?

来自分类Dev

工具栏标题不居中

来自分类Dev

更改工具栏中的标题颜色?

来自分类Dev

折叠工具栏标题消失

来自分类Dev

片段中的工具栏标题