Android的工具栏:在横向模式下小的标题文本 [英] Android Toolbar: small title text in landscape mode

查看:190
本文介绍了Android的工具栏:在横向模式下小的标题文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试了新的工具栏和AppCompat主题在Android和遇到一个问题。我的工具栏标题文字看起来正常大小的肖像模式,但它变得相当小的横向模式虽然我没有在code做任何更改标题的文字大小。以下是截图:

activity_main.xml:

 <! - 一个DrawerLayout拟用作使用match_parent的宽度和高度消耗的可用全空间的顶层内容视图。 - >
<的LinearLayout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    工具:上下文=com.techfunmyanmar.jujaka.ui.MainActivity>

    < android.support.v7.widget.Toolbar
        机器人:ID =@ + ID / main_toolbar
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:ATTR / colorPrimary后台=
        应用程序:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar
        应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>

    < android.support.v4.widget.DrawerLayout
        机器人:ID =@ + ID / drawer_layout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent>

        <! - 为主要内容的视图,该视图下方消耗整个
             使用match_parent在两个方向的可用空间。 - >
        <的FrameLayout
            机器人:ID =@ + ID /容器
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent/>

        <  - 安卓!layout_gravity =开始告诉DrawerLayout治疗
             此为在左侧的滑动抽屉左到右
             语言和右侧从右到左的语言。
             如果你还没有建立对API 17或更高,使用
             机器人:layout_gravity =左代替。 - >
        &所述;! - 抽屉中给出DP一个固定的宽度和延伸的整个高度
             该容器。 - >
        <片段
            机器人:ID =@ + ID / navigation_drawer
            机器人:名称=com.techfunmyanmar.jujaka.ui.NavigationDrawerFragment
            机器人:layout_width =@扪/ navigation_drawer_width
            机器人:layout_height =match_parent
            机器人:layout_gravity =开始
            工具:布局=@布局/ fragment_navigation_drawer/>
    < /android.support.v4.widget.DrawerLayout>
< / LinearLayout中>
 

styles.xml:

 <资源>
    <! - 基本应用主题。 - >
    <样式名称=AppBaseTheme父=Theme.AppCompat.Light.DarkActionBar>
        <项目名称=windowActionBar>假< /项目>

        <! - 自定义你的主题在这里。 - >
        <项目名称=colorPrimary> @色/初级< /项目>
        <项目名称=colorPrimaryDark> @色/ primary_dark< /项目>
        <项目名称=colorAccent> @颜色/重音和LT; /项目>

    < /风格>

    <! - 主要应用的主题。 - >
    <样式名称=AppTheme父=AppBaseTheme>

    < /风格>

    <样式名称=DrawerArrowStyle父=Widget.AppCompat.DrawerArrowToggle>
        <项目名称=spinBars>真< /项目>
    < /风格>
< /资源>
 

解决方案

我试图设置安卓工具栏的titleTextApperance ,但风格是不适用的;我意识到我使用的是AppCompat主题,所以我用应用:titleTextApperance 和风格现在被应用。它看起来像景观的小写字母是内置的 AppCompat.Toolbar.Title 的风格本身让我推翻它来手动设置字体大小的问题。最后code:

工具栏的XML:

 < android.support.v7.widget.Toolbar
        机器人:ID =@ + ID / main_toolbar
        机器人:layout_width =match_parent
        机器人:layout_height =?ATTR / actionBarSize
        机器人:ATTR / colorPrimary后台=
        应用程序:titleTextAppearance =@风格/ ToolbarTitle
        机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar
        应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>
 

工具栏风格:

 <样式名称=ToolbarTitle父=@风格/ TextAppearance.Widget.AppCompat.Toolbar.Title>
        <项目名称=机器人:TEXTSIZE> 20SP< /项目>
< /风格>
 

I'm testing the new Toolbar and AppCompat theme on Android and ran into a problem. My toolbar title text looks normal-sized on portrait mode but it became rather small on landscape mode although I didn't do anything in the code to change the title's text size. Here are the screen shots:

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>

解决方案

I tried to set android:titleTextApperance of the toolbar but the style wasn't applied and I realized I'm using the AppCompat theme so I used app:titleTextApperance and the style is now being applied. It looks like the small letters in landscape are a problem in the built-in AppCompat.Toolbar.Title style itself so I overrode it to set the font size manually. The final code:

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

Toolbar Style:

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

这篇关于Android的工具栏:在横向模式下小的标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆