I have been trying to set white text on the actionbar. I went through many questions and I am using theme Theme.AppCompat.Light.DarkActionBar and currently using this xml:
<style name="TrasnparentActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/TransparentActionBar</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<style name="TransparentActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/actionbar_transparent_background</item>
<item name="android:titleTextStyle">#style/TransparentTransparentActionBarText</item>
</style>
<style name="TransparentTransparentActionBarText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
</style>
I have tried different combinations for eg: setting android:titleTextStyle, actionmenutextcolor, or using the actionBar Style Generator. None are working for me.
The above code is from values-v11 but a similar code is in values folder too.
#drawable/actionbar_transparent_background is just a shape with <solid android:color="#00000000"/>
In order to have white text (so dark action bar with light theme) you have to inherit your actionbar style from the correct object: Widget.AppCompat.Light.ActionBar.Solid.Inverse and not Widget.AppCompat.ActionBar.Solid
Here is the style.xml file :
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- action bar -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
Related
I just can't figure this one out:
I have an application with an ActionBar, I want the ActionBar to be red and the background of the app blue. I tried to achieve this with this styles.xml:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/blue</item>
<item name="background">#color/blue</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/red</item>
<item name="background">#color/red</item>
</style>
But the actionBar is always blue. When I take away the blue background of the app, the actionBar is red as desired...
Any ideas?
The margin that you set is ambiguous and does not apply to anything. You should set the margin on your action bar theme:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/red</item>
<item name="android:windowBackground">#color/blue</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:layout_marginTop">5dp</item>
</style>
If all you're trying to do is a red action bar with a blue background, it is much easier to use the material properties included with v21+ of the support library:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/red</item>
<item name="android:windowBackground">#color/blue</item>
</style>
I am using "Theme.Light" theme for my android project and while setting up a navigation drawer how can i set actionbar size(height).
I used the below code and i got an error..
<style name="Theme.Light.ActionBar" parent="#android:style/Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="actionBarSize">36dip</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
can you please reply to my problem as soon as possible and thank you.
Use height attribute,for actionBarHeight
<item name="android:height">#dimen/bar_height</item>
you have to create style like this:
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<!-- native widgets will now be "tinted" with accent color -->
<item name="colorAccent">#color/accent</item>
<!--Action bar style-->
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:height">#dimen/bar_height</item>
</style>
<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">#dimen/bar_text_size</item>
<item name="android:textColor">#color/bar_text_color</item>
</style>
you have to try below code :
<resources>
<style name="Theme.FixedSize" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="actionBarSize">48dip</item>
<item name="android:actionBarSize">48dip</item>
</style>
</resources>
If you are using AppCompat, you can set the "actionBarSize" attribute in your theme (which must inherit from Theme.AppCompat.x). You can also use a Toolbar in your layout and set its layout_height to the desired value.
I followed the steps mentioned in Styling the Action Bar | Android Developers to change the colour of the action bar.
But I am getting weird action bar. The actionbar colour is changed to green but the text in actionbar has different background (white), the buttons in actionbar has different background (white).
The code I used is as follows:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#color/core_white</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:buttonStyle">#style/Button</item>
<item name="android:editTextStyle">#style/EditText</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/core_other</item>
<item name="android:backgroundStacked">#color/core_other_light</item>
<item name="android:backgroundSplit">#color/core_other</item>
</style>
Below are the screen shots of the theme I got:
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:buttonStyle">#style/Button</item>
<item name="android:editTextStyle">#style/EditText</item>
<item name="android:windowBackground">#android:color/black</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:backgroundStacked">#color/core_other_light</item>
<item name="android:backgroundSplit">#color/core_other</item>
<item name="android:background">#00ff00</item>
</style
>
Change background in app theme to windowBackground
More detail check :
https://developer.android.com/training/material/theme.html
I have used Material Theme you can use holo or other
try this
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
I am currently working on some changes to my app to properly target the new Android 5.0 Lollipop that has just been released.
I have the following in my styles.xml files in the values-v21 directory
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/actionBarTabStyle</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/appPrimaryColour</item>
</style>
<style name="actionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/white</item>
</style>
</resources>
I've changed the theme but I have customised my action bar with the following for the old Holo theme
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
and
<style name="actionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabText">
I can't find what the equivalent would be for Lollipop, I've tried #android:style/Widget.Material.Light.ActionBar.Solid.Inverse #android:style/Widget.Material.ActionBar.TabText" but it then says it can't find the resources.
Just extend from Theme.Material.Light.DarkActionBar, which sets up the action bar theme to point to Theme.Material (dark) values for background and foreground colors. Also, you should be setting colorPrimary, colorPrimaryDark, and colorAccent in your AppTheme rather than manually setting the action bar background color.
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:colorPrimary">#color/appPrimaryColour</item>
<item name="android:colorPrimaryDark"> ... </item>
<item name="android:colorAccent"> ... </item>
</style>
i'm trying to create the a flat action bar without shadow
attached image:
my style xml
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:background">#drawable/white_bg</item>
<item name="android:displayOptions"></item>
</style>
I'm supporting android 4.x
Any ideas ? I tried changing the style to Solid/Inverse didn't work..
white_bg attached (It's hard to see since it's white)
it should look like this
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:background">#drawable/white_bg</item>
<item name="android:displayOptions"></item>
</style>
The null windowContentOverlay attribute should be set on your Activity theme (CustomActionBarTheme), not on the ActionBar theme.