gpt4 book ai didi

java - 如何为多种屏幕尺寸设置操作栏和标题窗口文本大小?

转载 作者:太空宇宙 更新时间:2023-11-04 14:41:59 25 4
gpt4 key购买 nike

我想根据屏幕尺寸和分辨率(例如 4"480 x 800 hdpi)设置操作栏的文本大小。我的应用程序开发已经结束,所以现在我只是确保应用程序布局适合所有多个 Android 屏幕尺寸。问题是我无法设置每个布局的标题大小,例如布局正常 hdpi 和布局正常 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>

最佳答案

我认为这个问题类型的最佳解决方案,以及维度的值(value)

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

//改成这个

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

编辑:

在这里查看更多: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>

关于java - 如何为多种屏幕尺寸设置操作栏和标题窗口文本大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24844183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com