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.
Related
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>
This question already has answers here:
ActionBar text color
(28 answers)
Closed 7 years ago.
I want to change the Color of my action Bar instead of white text I want #59380d so I added the color to a color.xml like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#59380d"/>
</selector>
And Then I call it into my styles.xml like this:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:textColor">#color/header</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textColor">#color/header</item>
</style>
</resources>
And finally at my AndroidManifest I set it the aplication like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name="com.app.activities.MyAp"
android:theme="#style/AppTheme" >
...
</aplication>
But the text of the Action Bar still White. What I'm doing wrong
For Android 3.0 and higher you need to override:
<style name="CustomActionBarTheme" parent="#style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
For 2.1 and higher:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat">
<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.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<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/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
To cHange The Text COlor
ActionBar actionBar = getActionBar();
actionBar.setTitle(Html
.fromHtml("<font color='#59380d'> Your Text </font>"));
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>
How to change the color of Action Bar Back Button and Action bar Menu Icon(Image attached).
I have the following style code(below), using which I customized the Text but I'm not able to completely customize the Action Bar.
Below is the Style code which I have used :
<style name="MyCustomTheme" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="background">#drawable/bg_header</item> -----------(1)
<item name="android:background">#drawable/bg_header</item>
<item name="android:titleTextStyle">#style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item> ----(2)
<item name="titleTextStyle">#style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item>
<item name="android:homeAsUpIndicator">#style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item>
</style>
<style name="customTextAppearance.Sherlock.Widget.ActionBar.Title" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textSize">18dp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:shadowColor">#ffffff</item>
<item name="android:shadowDy">3</item>
<item name="android:textStyle">bold</item>
</style>
Your help will be appreciated, Thank you.
Just find proper icons for your actionbar and customize it...
and then make changes in your...
You Can Do Following For Changing Icons Of Actionbar
style.xml
<style name="Widget.ActionButton.Overflow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_overflow</item>
</style>
<style name="Your.Theme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionOverflowButtonStyle">#style/Widget.ActionButton.Overflow</item>
<item name="android:homeAsUpIndicator">#drawable/my_fancy_up_indicator</item>
</style>
check out this page on android help https://developer.android.com/training/basics/actionbar/styling.html
When supporting Android 3.0 and higher only,
you can define the action bar's background like this: 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>
Then apply your theme to your entire app or individual activities:
<application android:theme="#style/CustomActionBarTheme" ... />
For Android 2.1 and higher
When using the Support Library, the same theme as above must instead look like this:
res/values/themes.xml
<?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>
Then apply your theme to your entire app or individual activities:
<application android:theme="#style/CustomActionBarTheme" ... />
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>