Search code examples
androidandroid-theme

Styles and themes in Android


I'm trying to learn something about styles and themes for 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. 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?


Solution

  • 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>