Cris
Cris

Reputation: 12194

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?

Upvotes: 1

Views: 704

Answers (2)

hackbod
hackbod

Reputation: 91321

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>

Upvotes: 3

BFil
BFil

Reputation: 13096

It's easy to do, just read the official reference:

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)

Upvotes: 0

Related Questions