我正在使用工具栏,在其上设置标题文本。但是对于不同的屏幕,我使用样式定义了不同的标题文本大小。
但问题是,当我在屏幕为 mdpi
的手机上运行时,标题文本大小正常,但对于 tablet mdpi
屏幕,标题看起来太小
这是我的风格
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">15dp</item>
<item name="android:textStyle">bold</item>
</style>
这是工具栏.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="50dp"
app:titleTextAppearance="@style/Toolbar.TitleText"
android:subtitleTextAppearance="@style/AppTheme.Toolbar.SubTitle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
我已在所有文件夹中声明此样式,例如 style.xml(mdpi)
、style.xml(hdpi)
、style.xml(xhdpi)
具有不同的文本大小。
所以请帮助我如何设置标题的文本大小,使其在手机和平板电脑上看起来都不错
最佳答案
在所有dimens.xml中
<dimen name="myTextSize">xxxxxsp</dimen>
在values/style.xml
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">@dimen/myTextSize</item>
</style>
关于android - 工具栏标题文字大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43136919/