I have a one activity and one layout application. I am implementing ActionBarSherlock, but my theme isn't applying to my emulator/early devices.
My theme.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActivityTheme" parent="Theme.Sherlock">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- other activity and action bar styles here -->
</style>
<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:backgroundSplit">#4200ff</item>
<item name="android:backgroundStacked">#4200ff</item>
<item name="android:background">#4200ff</item>
</style>
</resources>
This causes the ActionBar on my JellyBean device to turn blue, but it stays black on my 2.2 emulator.
Here is a piece from my manifest.xml:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomActivityTheme">
In Android version 3.0 and later you can assign theme to to item name android:actionBarStyle. But in 2.3 and earlier there is no Action Bar, so you can't use item with name android:actionBarStyle. To fix this ActionBarSherlock has defined it's own item name just actionBarStyle without android prefix.
So your code should look like this
<!-- the theme applied to the application or activity -->
<style name="CustomActivityTheme" parent="Theme.Sherlock">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<!-- other activity and action bar styles here -->
</style>
<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:backgroundSplit">#4200ff</item>
<item name="android:backgroundStacked">#4200ff</item>
<item name="android:background">#4200ff</item>
</style>
Related
This question already has an answer here:
Change Android 5.0 Actionbar color
(1 answer)
Closed 7 years ago.
I'm trying to change background color of action bar in my app and my styles.xml looks that:
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimary">#71343e</item>
<!-- theme UI controls like checkboxes and text fields -->
<!-- native widgets will now be "tinted" with accent color -->
<item name="colorAccent">#ff71bf41</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">100dp</item>
<item name="android:colorBackground">#71343e</item>
</style>
<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#0d5875</item>
</style>
I'have tryed to use various color argument but anyone work. How I can change the ActionBar color?
For android version 3.0+, this is one solution:
inside res/values/themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<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:background">#drawable/actionbar_background</item>
</style>
</resources>
And set it to your whole application (or individual activities)
<application android:theme="#style/CustomActionBarTheme" ... />
For android version 2.1+, you have to modify it a bit
<?xml version="1.0" encoding="utf-8"?>
<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">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
And
<application android:theme="#style/CustomActionBarTheme" ... />
You can find more information about styling the ActionBar here.
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>
i want to change my action bar background to become tranparent but not overlay, because i want to make my action bar get its backround from activity background and just have border-bottom to separate it from activity .
i have try to make custom style with action bar background transparent but its become gray.
this is my custom style
<?xml version="1.0" encoding="utf-8"?>
<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>
<item name="android:actionMenuTextColor">#color/putih</item>
<item name="android:homeAsUpIndicator">#drawable/navigation_previous_item</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionMenuTextColor">#color/putih</item>
<item name="homeAsUpIndicator">#drawable/navigation_previous_item</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#android:color/transparent</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<item name="background">#android:color/transparent</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/putih</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
Thank for your help
So I'm new to app developing and currently following a developer's guide on android.com. I'm stuck on "stylizing your actionBar" part, because the code suggested on the website doesn't work:
<?xml version="1.0" encoding="utf-8"?>
<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">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
I get the compatibility error about android:backgound that can't be used since my minSdk is 7 (though the guide claims it should work).
I don't want to change my minSdk, and I tried splitting the themes.xml into 2, one I put into values, and the other into values-v11. The error doesn't occur anymore, but when I run the app the actionBar doesn't change its backgroud. Here are the both files:
this one is in values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
and this one is in values-11
<?xml version="1.0" encoding="utf-8"?>
<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>
</style>
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FFB300</item>
</style>
</resources>
Do you have any idea what's the problem here?
The API lvl on my device is 21
As of AppCompat v21, the android: attributes are no longer used. It also supports color theming, which provides a very easy way to set the color of the action bar (and status bar on Android 5.0 devices) using a very simple theme:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/my_awesome_color</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/my_awesome_darker_color</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
</style>
I have searching a lot a method to customize the Action Bar.
Basically I need to give color, text color to the action bar and color, text color, underline color to the navigation tabs of the action bar (they are under action bar).
So I have prepared a XML style file that is the following. You can see that in the second block there are all the reference to the text styles and navigation tabs styles
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyTheme.ActionBar" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles: inherit the parent theme and override it with other themes -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#6b3f8f</item> <!-- #5b327c -->
<!-- <item name="android:titleTextStyle">#style/MyActionBarTitleText</item> -->
<item name="android:actionBarTabStyle">#style/tabStyle</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#FFFFFF</item>
</style>
<!-- navigations tabs styles -->
<style name="tabStyle" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#000000</item>
<item name="android:backgroundStacked">#000000</item>
<item name="android:backgroundSplit">#000000</item>
</style>
The color of the ActionBar is changing but not the others, why? I think to have extended the properties well. This is my manifest:
<!-- #android:style/Theme.Holo.Light -->
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme.ActionBar"
android:allowBackup="true">
.....
</aplication>
android:backgroundStacked and android:backgroundSplit should be placed under MyActionBar, not your tab style because they're both inherit of Widget.Holo.ActionBar.