Reputation: 23
I'm new to Android development, but I found really hard understanding how to style my apps using XML in "res/values/styles.xml".
In all the tutorials I found it seems that you can just inherit most of the style by declaring the "parent" field in tag, then change what you need to.
However most of the styles inherited in that way are non-public and recent restrictions on styling android Apps make inheritance of non-public styles nearly impossible.
I said "nearly" because I found solutions involving in lots of copy-paste from "Styles.xml" in the android SDK. a clear example, found here on StackOverflow is:
http://android-argentina.blogspot.it/2011/08/error-retrieving-parent-for-item.html
applying these solutions, my simple xml:
<style name="MyActionBar" parent="@style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
became:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar">
<!--copied from Widget.Holo.Light.ActionBar.Solid.Inverse -->
<item name="android:titleTextStyle">
@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse
</item>
<item name="android:subtitleTextStyle">
@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle.Inverse
</item>
<item name="android:background">@android:drawable/ab_solid_dark_holo</item>
<item name="android:backgroundStacked">@android:drawable/ab_stacked_solid_dark_holo</item>
<item name="android:backgroundSplit">@android:drawable/ab_bottom_solid_inverse_holo</item>
<item name="android:divider">@android:drawable/list_divider_holo_dark</item>
<item name="android:progressBarStyle">@android:style/Widget.Holo.ProgressBar.Horizontal</item>
<item name="android:indeterminateProgressStyle">@android:style/Widget.Holo.ProgressBar</item>
<item name="android:progressBarPadding">32dip</item>
<item name="android:itemPadding">8dip</item>
<!-- custom items -->
<item name="android:background">#FF0000</item>
</style>
At this point resouces like "@android:drawable/ab_bottom_solid_inverse_holo" are not public, and others cannot be fond inside the project (yes, even if they were "@android:drawable/SOMETHING") and will cause compiling errors, so this solution, found nearly everywhere in internet, just doesn't solve the problem at all.
I just wanted to change the background of an action bar without loosing all the base style, there MUST be an easy and smart way to do it.
So please help, there must be something stupid that i don't consider.
(sorry for my bad english)
Upvotes: 2
Views: 997
Reputation: 1336
Try this:
<style name="YourCustomTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/Widget.Holo.ActionBar.XYZ</item>
</style>
<style name="Widget.Holo.ActionBar.XYZ" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@color/aw_blue</item>
</style>
Upvotes: 2