简体   繁体   English

如何为多个屏幕尺寸设置操作栏和标题窗口的文本尺寸?

[英]How do you set the action bar and title window text size for multiple screen sizes?

I want to set the text size of the action bar based on the screen size and resolution such as 4" 480 x 800 hdpi. I'm at the end of my app development so now I'm just making sure the app layout fits in all the multiple android screen sizes. The problem is that I can't set the title size per layout such as layout-normal-hdpi and layout-normal-ldpi so in some device layouts the text I place in the title text runs out of space since the text is too big when test it on an emulator. Here's the styles.xml code. 我想根据屏幕尺寸和分辨率(例如4“ 480 x 800 hdpi)设置操作栏的文本大小。我处于应用开发的最后阶段,因此现在我要确保应用布局适合所有多个android屏幕尺寸。问题是我无法为每个布局设置标题大小,例如layout-normal-hdpi和layout-normal-ldpi,因此在某些设备布局中,我放置在标题文本中的文本用完了空格,因为在模拟器上测试文本时文本太大。这是styles.xml代码。

<style name="ActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:background">@color/title_background</item>
<item name="android:titleTextStyle">@style/TextMedium</item>
<item name="android:displayOptions">showTitle</item>
</style>

<style name="TextMedium">
    <item name="android:textSize">16sp</item>
</style>

I think the best aborgem for this problem type, and the value in dimension 我认为这种问题类型的最佳仿生品,以及维度的价值

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="font_size">16sp</dimen>
</resources>

//change to this //更改为此

<style name="TextMedium">
    <item name="android:textSize">@dimen/font_size</item>
</style>

Edited: 编辑:

see more here : https://developer.android.com/training/basics/actionbar/styling.html 在此处查看更多信息: https : //developer.android.com/training/basics/actionbar/styling.html

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <!-- the theme applied to the application or activity -->
    <style name="AppThemeApp" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/background_actionbar</item>
        <item name="background">@color/background_actionbar</item>
        <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>

        <!-- Support library compatibility -->
        <item name="titleTextStyle">@style/MyActionBarTitleText</item>
    </style>

    <!-- ActionBar title text -->
    <style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/actionbar_text</item>
        <item name="android:textSize">@dimen/font_size</item>
        <!-- The textColor property is backward compatible with the Support Library -->
    </style>
</resources>

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

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