简体   繁体   English

如何设置带有不同大小文本的android主题?

[英]How do I set up an android theme with different sizes of text?

I have been browsing around, in an attempt to understand android themes. 我一直在浏览,以了解Android主题。 I understand how to create and apply styles, unfortunately when it comes to themes, my brain just doesn't quite get it. 我了解如何创建和应用样式,不幸的是,谈到主题时,我的大脑还不太了解。 Maybe it's because I come from a web-developer background, so my brain hasn't quite "re-wired" itself for android yet. 也许是因为我来自网络开发人员背景,所以我的大脑还没有完全“重新连接” Android。

I'd like to do as little redundant work as possible, so i decided that my theme would have different text-sizes based on whether it's a header, a text-body or a small text(designer wants text to be bigger on some screen sizes). 我想尽量减少多余的工作,因此我决定根据主题是标题,文本主体还是小文本(主题,设计师希望在某些屏幕上放大文本),使主题的文本大小不同大小)。 This way I can easily create different width-based layouts with different sizes of text depending on whether we are on a tablet or phone(instead of having to edit every single layout-file and TextView). 这样,根据我们是在平板电脑还是手机上,我可以轻松地创建具有不同大小的文本的基于宽度的不同布局(而不必编辑每个布局文件和TextView)。

Can anyone help me understand how I should do this? 谁能帮助我了解我该怎么做? The android developer's guide just confuses me. Android开发人员指南只是让我感到困惑。

您可以在styles.xml中设置textAppearance项,如下所示;

<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>

So, you can set up different styles in Android in your styles.xml file, if you wanted a different style for a title and header you would create two separate styles like so; 因此,您可以在Android的styles.xml文件中设置不同的样式,如果您想要标题和标头使用不同的样式,则可以创建两个单独的样式,如下所示:

<style name="Title">
    <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
</style>

<style name="Header">
    <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
</style>

Then in your layout file you can use these styles like so; 然后,可以在布局文件中使用以下样式:

<TextView
            android:id="@+id/title"
            style="@style/Title" />

Or you can set a global style to all TextViews like so; 或者,您可以像这样为所有TextView设置全局样式;

<style name="MyTheme" parent="android:Theme">
<item name="android:textViewStyle">@style/Title</item> </style>

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

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