简体   繁体   English

Android 中的样式和主题

[英]Styles and themes in Android

I'm trying to learn something about styles and themes for Android.我正在尝试了解有关 Android 样式和主题的知识。 I've found that, if I add the android:theme attribute in the manifest for Application or Activity, style is applied to the entire app/activity.我发现,如果我在应用程序或活动的清单中添加android:theme属性,样式将应用于整个应用程序/活动。 I think it would be useful to be able to define a style that is applied for example only to buttons.我认为能够定义仅应用于按钮的样式会很有用。 Do you know if there is a way to apply a certain style only for a certain kind on Views, as in CSS?您是否知道是否有一种方法可以像在 CSS 中那样,仅将某种样式应用于视图上的某种类型?

Here's a general example:这是一个通用示例:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomButton" parent="@android:style/Widget.Button">
        <item name="android:textColor">#FF0000</item>
    </style>
    <style name="CustomTheme" parent="android:Theme">
        <item name="android:buttonStyle>@style/CustomButton</item>
    </style>
</resources>

It's easy to do, just read the official reference:很容易做到,只需阅读官方参考:

http://developer.android.com/guide/topics/ui/themes.html http://developer.android.com/guide/topics/ui/themes.html

EDIT编辑

Obviously you'll need to specify the style you create on each button/view you want it to be applied (like in css, for the class attribute)显然,您需要指定在您希望应用的每个按钮/视图上创建的样式(如在 css 中,对于 class 属性)

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

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