首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android工具栏:横向模式下的小标题文本

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

Stack Overflow用户
提问于 2015-01-20 17:55:39
回答 4查看 21K关注 0票数 61

我正在安卓系统上测试新的工具栏和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>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-01-21 07:12:50

我尝试设置工具栏的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>
票数 108
EN

Stack Overflow用户

发布于 2015-04-30 06:12:07

AOSP Issue #170707是关于标题和副标题文本大小的更改编写的。项目成员的回应是“按预期工作。与框架行为相同。”虽然我不认为更改文本大小是理想的默认行为,但听起来AppCompat工程师必须保持与(有缺陷的)框架行为的一致性。然后,开发人员就可以按照Chilly Chan的回答来覆盖默认样式。

补充Chilly Chan的答案:

1)通过定义从TextAppearance.Widget.AppCompat.Toolbar.Subtitle.派生的另一种样式,可以以类似的方式控制字幕文本大小

2)纵向的标题/字幕大小默认值为20dp/16dp (在我的Galaxy S3上为4.4.2.)。Chilly Chan的例子指定了"17sp“。仅当您想让用户首选项设置影响标题/副标题大小时,才使用"sp“。

票数 11
EN

Stack Overflow用户

发布于 2015-01-20 18:05:38

尝试将其添加到activity_main.xml下的工具栏部分。

android:minHeight="?android:attr/actionBarSize“

我还注意到你使用的是标准的深色动作栏,建议使用没有动作栏的主题,定义了一个新的工具栏

 Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);

<android.support.v7.widget.Toolbar
    android:id=”@+id/my_awesome_toolbar”
    android:layout_height=”wrap_content”
    android:layout_width=”match_parent”
    android:minHeight=”?attr/actionBarSize”
    android:background=”?attr/colorPrimary” />
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28042331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档