views:

55

answers:

2

Here they write:

To apply a style definition as a theme, you must apply the style to an Activity or application in the Android manifest. When you do so, every View within the Activity or application will apply each property that it supports. For example, if you apply the CodeFont style from the previous examples to an Activity, then all View elements that support the text style properties will apply them.

So, when I set TextColor to Red, do ALL Elements with Text change to red?? Arent there powerful specifier like in CSS style-sheets? I just see the concept of styles (style="@style/CodeFont") practicable.

1: http://developer.android.com/guide/topics/ui/themes.html#ApplyingStylesemphasized text

+1  A: 

If you read just below the text you quoted:

To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit the tag to include the android:theme attribute with the style name

If you want a theme applied to just one Activity in your application, then add the android:theme attribute to the tag instead.

And a little bit after that, it describes how to inherit and override properties, just like CSS:

If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional dialog theme to use your own background image like this:

<style name="CustomTextView" parent="@android:style/Widget.TextView">
    <item name="android:background">@drawable/custom_background</item>
</style>

Then, to interit from CustomTextView

<style name="CustomTextView.RedText">
   <item name="android:textColor">@color/red</item> 
</style>

Once designing the XML layout, you can inherit a theme and override the properties

<TextView
    android:id="@+id/example"

    style="@style/CustomTextView.RedText"

    android:textColor="@color/green" />

I think you should read again the page you yourself linked, it's well explained :)

Maragues
So, in both cases, I have to set the style attribute in the actual element?
OneWorld
You can also set the style in the manifest. An <activity> or an <application> may have a theme, which can be overridden later.
Maragues
So, what can I style, when setting a theme to an activity? Can I say smth like "All Buttons have red Text and all TextViews have blue, small Characters"? You know what I mean by refering to CSS?
OneWorld
I'm not a CSS expert, I know the basis. In Android, I don't think you can define "All buttons have red text" in a theme. You can create a template like <style name="MyButton" parent=".../Widget.Button"> and then each time you use a button set the style=@style/MyButton. It would be interesting if you could define a set of themes in a .xml and then apply it to the application, but I've never seen that.
Maragues
OK, so far I don't see any benefit of using themes compared to styles because they are too unspecified. Nobody wants all text to be red in his app. For my opinion it just makes sense for attributes like background.
OneWorld