java TextColor vs TextColorPrimary vs TextColorSecondary

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39070040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:03:47  来源:igfitidea点击:

TextColor vs TextColorPrimary vs TextColorSecondary

javaandroidthemestextcolor

提问by rafvasq

What do each of these encompass in terms of text throughout an app?

就整个应用程序的文本而言,这些都包含哪些内容?

More specifically, what would changing each of these in a theme change throughout my app? I'd like my buttons' texts to be a different color than my textviews; is one primary and the other secondary?

更具体地说,在我的应用程序中更改主题中的每一个会发生什么变化?我希望按钮的文本与文本视图的颜色不同;一个是主要的,另一个是次要的?

Any info related to these terms is appreciated!

感谢您提供与这些条款相关的任何信息!

回答by Ryan Pierce

TextColor is just the xml attribute to set a color to the text of any given view.

TextColor 只是为任何给定视图的文本设置颜色的 xml 属性。

TextColorPrimary is the default text color for enabled buttons and Large Textviews.

TextColorPrimary 是已启用按钮和大文本视图的默认文本颜色。

TextColorSecondary is the default text color for Medium and Small Textviews.

TextColorSecondary 是中小文本视图的默认文本颜色。

Ignore this, as for what you want to do, there is a better way. You want to edit your style.xml such that the default theme AppTheme (or whatever else you have declared as your theme in your manifest) contains the necessary xml attributes to customize your text colors.

忽略这个,至于你想做什么,还有更好的方法。您想编辑 style.xml 以便默认主题 AppTheme(或您在清单中声明为主题的任何其他内容)包含必要的 xml 属性以自定义您的文本颜色。

The resulting AppTheme style will look like this when youre done.

完成后,生成的 AppTheme 样式将如下所示。

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColor">#hexColorForTextViews</item>
    <item name="android:buttonStyle">@style/myDefaultButton</item>
</style>

textColor will set the default color for all of your textviews. buttonStyle will reference a custom style that you want for all of your buttons. To make this work, add this style tag to your styles.xml file.

textColor 将为您的所有文本视图设置默认颜色。buttonStyle 将引用您想要的所有按钮的自定义样式。要使此工作正常运行,请将此样式标记添加到您的 styles.xml 文件中。

<style name="myDefaultButton">
    <item name="android:textColor">#hexColorForButtons</item>
    <!-- other stuff you want your buttons to inherit by default -->
</style>