Unable to Style ActionBar Android AppCompat - android

I've included my theme in the Manifest file. My theme's code is as follows
<resources>
<!-- Activity themes -->
<style name="Theme.Base" parent="Theme.AppCompat.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<style name="AppTheme" parent="Theme.Sample" >
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/blue</item>
</style>
</resources>
All my activities inherit ActionBarActivity
I can't seem to change the color of my ActionBar.
Please help.
I am running this on an emulator with API 21.
How can I style my ActionBar?

The AppCompat v21 doesn't read any android: attributes related to the action bar:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Here we setting appcompat’s actionBarStyle -->
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">#color/my_awesome_red</item>
<item name="colorPrimaryDark">#color/my_awesome_darker_red</item>
<!-- The rest of your attributes -->
</style>

You can change the color adding this code to your style:
<item name="colorPrimary">#android:color/holo_red_dark</item>
With colorPrimaryDark you can change the status bar color.
Take care, use colorPrimary, dont use android:colorPrimary, this last only works with 21.
All code:
<resources>
<!-- Activity themes -->
<style name="Theme.Base" parent="Theme.AppCompat.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<style name="AppTheme" parent="Theme.Sample" >
<item name="colorPrimary">#android:color/holo_red_dark</item>
</style>
</resources>

I found this Google Blog Post for the v21 appCompat extremly helpful. It explains the usage pretty good.

You can do this by below way
Simply edit the res/values/styles.xml file of your Android project.
For example like this:
<resources>
<style name="MyCustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
or by java code
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED));

Related

How can I change statusbar color without a toolbar?

I'm trying to make the status bar color #a1a1a1 (white_dark) but it's just black when i run it.
This is my Style v21 file:
<style name="AppBaseTheme" parent="AppTheme">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/white_dark</item>
</style>
you can try this lib
But my personal suggestion is, switch to AppCompatbecause its very easy to change StatusBar color in it.
Primary Dark color is used for StatusBar:
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#android:color/black</item>
use this theme
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/atctionbar_color</item>
<!-- Support library compatibility -->
<item name="background">#color/atctionbar_color</item>
</style>
</resources>
and create new file in values>colors.xml and add color from there
<resources>
<color name="atctionbar_color">#170053</color>
</resources>

Styling the android action bar?

I'm trying to style the action bar inside my app using the code below.
<resources>
<!-- the theme applied to the application or activity -->
<style name="myTheme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:textSize">24sp</item>
</style>
simply put the font should be bigger.. but nope.
Any ideas as to why?
Thanks.
Possibly your theme is not applied to activity. Set it in manifest:
<activity
android:name=".YourActivty"
android:theme="#style/myTheme" />
UPDATE 1
You should change action bar text size in such way (changing titleTextStyle):
<style name="Theme.YourTheme" parent="android:style/Theme">
<item name="android:actionBarStyle">#style/Theme.YourTheme.Styled.ActionBar</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar">
<item name="android:titleTextStyle">#style/Theme.Viadeo.Styled.YourTheme.TitleTextStyle</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar.TitleTextStyle" parent="#android:style/Widget.TextView">
<item name="android:textSize">24sp</item>
</style>

Changing the colour of ActionBar in Android

Here is my xml code in styles.xml to change theme and colour of ActionBar.
<?xml version="1.0" encoding="utf-8"?>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#drawable/brand_logo</item>
<item name="android:background">#ff5d44</item>
</style>
Here is the documentation. My app supports API level 11 and higher. Not sure where I am going wrong. Please help.
set "AppTheme" as theme for application / activity.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#android:color/white</item>
</style>
For more check THIS ,THIS and THIS
I was using support library. So here is the fix.
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#ff5d44</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!--Support library compatibility-->
<item name="background">#color/orange</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>

How to change the action bar background color using Appcompat

Yes, I know there are a lot of similar questions and answers in the internet. I checked all of them for the last three hours. No solution worked for me.
I simply started an Android Studio (v1.0.2) Project, which is by default provided by the v7 AppCompat Library.
I changed styles.xml to:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/MyAppTheme">
<item name="android:background">#android:color/holo_red_dark</item>
</style>
</resources>
... and inside AndroidManifest.xml:
android:theme="#style/MyAppTheme"
I'm looking for the easiest way to change the background color of the Action Bar globally to a desired color.
Right now the action bar is completely white with three black dots for the menu button.
With Appcompat rel 21.0.x just use something like:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s color theming attrs -->
<item name=”colorPrimary”>#color/my_color</item>
<item name=”colorPrimaryDark”>#color/my_color_darker</item>
</style>
If you want to override the actionBarStyle attribute use:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- ... -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- default value is #null -->
<item name="background">....</item>
</style>

Theme.AppCompat.Light.DarkActionBar giving black actionbar title text

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>

Categories

Resources