<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/bg_action_bar</item>
<item name="android:background">#drawable/bg_action_bar</item>
<item name="android:textColor">#color/my_red</item>
</style>
<style name="My_Style" parent="style/Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/ic_action_back</item>
<item name="homeAsUpIndicator">#drawable/ic_action_back</item>
</style>
What is the difference between 'homeAsUpIndicator' and 'android:homeAsUpIndicator' or 'background' and 'android:background' ?
I wonder if I need to set them both? I just found these examples, but could not find what you are setting when you don't use the 'android' namespace...
Due to limitations in Android's theming system any theme
customizations must be declared in two attributes. The normal
android-prefixed attributes apply the theme to the native action bar
and the unprefixed attributes are for the custom implementation. Since
both theming APIs are exactly the same you need only reference your
customizations twice rather than having to implement them twice.
The easiest way to convey exactly what this entails is with an example. The following is the full theme from the “Styled” example mentioned above:
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
Read more about ActionbarSherlock's Mirrored Attributes
Related
I make ActionBar in app.I change ActionBar style.There are some questions.
I want to change the title in the ActionBar.
So I write the follow code.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
<item name="actionOverflowButtonStyle">#style/overflowButton</item>
</style>
<!--ActionBar-->
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bg</item>
<item name="background">#color/bg</item>
<item name="android:title">#string/test</item>
<item name="title">#string/test</item>
</style>
<style name="overflowButton">
<item name="android:src">#mipmap/ic_add_black_48dp</item>
<item name="android:showAsAction"></item>
</style>
</resources>
when I only write <item name="android:title">#string/test</item> ,it doesn't work,but write <item name="title">#string/test</item> it work.
I have try to solve in Android Developer,but fail.Please help me.
<item name="title">#string/test</item>
this tag works on supporting library, and
<item name="android:title">#string/test</item>
this one works on your android. For more detail please have a look on here
I hope you understand, If not please let me know.
Note: If you are using the Support Library APIs for the action bar, then you must use (or override) the Theme.AppCompat family of styles (rather than the Theme.Holo family, available in API level 11 and higher). In doing so, each style property that you declare must be declared twice: once using the platform's style properties (the android: properties) and once using the style properties included in the Support Library (the appcompat.R.attr properties—the context for these properties is actually your app).
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)
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>
I have an Activity with a dark ActionBar. I need to remove its vertical dividers since my icons already have "built-in" dividers.
What I've tried goes below
Activity style:
<style name="sMain" parent="#android:style/Theme.Holo">
<item name="android:icon">#android:color/transparent</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
MyActionBar:
<style name="MyActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:actionBarDivider">#null</item>
</style>
This doesn't have any effect. Any ideas what I'm doing wrong?
You need to set the android:actionBarStyle attribute as part of the activity theme, not as part of the action bar style.
So I believe this should work:
<style name="sMain" parent="#android:style/Theme.Holo">
<item name="android:icon">#android:color/transparent</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarDivider">#null</item>
</style>
How to tell where attributes belong? I used to struggle with this too (usually solved by trial-and-error) until I discovered the use of the android.R.styleable class! Have a look here: https://developer.android.com/reference/android/R.styleable.html
If you do a search in the page for actionBarStyle you will see it shows up as Theme_actionBarStyle, meaning it is part of the Theme style (remember there is no technical difference between a theme and a style). If you do a search on ActionBar_ you will be able to iterate through all of the attributes that can be set as part of an ActionBar style.
I want to overload how an android Button looks, except I want to overload only one attribute i.e. the android:background. I know I could write something like:
<style name="App_TextButtonStyle" parent="???">
<item name="android:background">#drawable/filled_roundededges_nostroke</item>
</style>
Where parent="???" specifies which style I inherit from. My question is which style should I inherit from do that I get everything from the android default style for buttons and just define a new background.
I have used style for buttons without specifying "parent" attribute
<style name="BigButtonStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:background">#drawable/backbutton</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">8pt</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_margin">10pt</item>
</style>
I think it could be enough for you to define your style without "parent".
This is mostly for future visitors, I found a solution to the problem:
<style name="App_TextButtonStyle" parent="#android:style/Widget.Button">
<item name="android:background">#drawable/filled_roundededges_nostroke</item>
</style>
#android:style/Widget.Button references the default style of the button in the currently selected theme. You could also use the holo widget button style #android:style/Widget.Holo.Button (available since api 11).
You might want to look in <android-sdk-install-folder>/platforms/android-XX/data/res/values for the files styles.xml and themes.xml to check out all styles android uses for a given platform version.
Is there any way to make a style inherit from multiple other styles, instead of just being limited to:
<style name="WidgetTextBase">
<item name="android:typeface">serif</item>
<item name="android:textSize">12dip</item>
<item name="android:gravity">center</item>
</style>
<style name="BOSText" parent="WidgetTextBase">
<item name="android:textColor">#051C43</item>
</style>
I would like BOSText to also inherit from:
<style name="WidgetTextHeader">
<item name="android:textStyle">bold</item>
<style>
Styles do not support multiple inheritance (at least not as of Android 3.2).
The official docs say:
If you use the dot notation to extend a style, and you also include
the parent attribute, then the parent styles override any styles
inheritted through the dot notation.
You can only inherit one style. However, you can also make the inherited style inherit from another style, and so on:
<style name="WidgetTextBase">
<item name="android:typeface">serif</item>
<item name="android:textSize">12dip</item>
<item name="android:gravity">center</item>
</style>
<style name="WidgetTextHeader" parent="WidgetTextBase">
<item name="android:textStyle">bold</item>
</style>
<style name="BOSText" parent="WidgetTextHeader">
<item name="android:textColor">#051C43</item>
</style>
You can't inherit more than one style, but you can set up an inheritance chain.
For those who was looking for solution to just merge multiple different styles into one, you can use
public void applyStyle (int resId, boolean force)
https://developer.android.com/reference/android/content/res/Resources.Theme#applyStyle(int,%20boolean).
And apply it that way
context.theme.applyStyle(R.style.MyAdditionalStyle, false)
Whenever you specify true as second argument, it overrides existing values in your theme, and when false it adds only non-overlapping values from R.style.MyAdditionalStyle
I haven't tested scenario with multiple styles yet, but according to docs you can achieve it. So that's how this approach can be used as an alternative to multiple inheritance.
There is a parent attribute on the style tag that should let you inherit from other styles...
i.e.
<style name="CodeFont" parent="#style/WidgetTextBase">
<item name="android:textStyle">bold</item>
</style>
http://developer.android.com/guide/topics/ui/themes.html