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.
Related
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>"));
I had previously set the colour of my window background to white and now I am trying to change the colour of just the action bar to green. This is my xml code:
<style name = "CustomAppTheme2" parent = "android:Widget.Holo.Light">
<item name="android:windowBackground">#color/white</item>
<item name="android:background">#color/green</item>
<item name="android:icon">#android:color/transparent</item>
</style>
The problem is that using android:background to change the colour of the action bar, it overflows and changes the colour of the whole screen to green. I want a clear-cut green action bar and a white window below it. Thanks in advance!
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/CustomActionBarTheme">
<!-- Customize your theme here. -->
</style>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<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/top_bar_blue</item>
<!-- Support library compatibility -->
<item name="background">#drawable/top_bar_blue</item>
<item name="titleTextStyle">#style/myTheme.ActionBar.Text</item>
</style>
<!-- ActionBar Text -->
<style name="myTheme.ActionBar.Text" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:fontFamily">sans-serif-bold</item>
</style>
<!-- In Manifest -->
android:theme="#style/AppTheme"
You could extend ActionBarActivity from one of your classes and do something like this:
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
//Change the color of the actionbar by changing the value in the next line
actionBar.setBackgroundDrawable(new ColorDrawable(#FFFFFF));
How do I make the ActionBar title uppercase? Some answers suggest putting <item name="android:textAllCaps">true</item> but this has no effect when I put it in the actionBar style or actionBar's titleTextStyle. It only has an effect when I put in in the AppTheme style but that makes a bunch of things in my app also in all caps which I don't want.
My styles:
<style name="AppTheme" parent="AppBaseTheme">
<!-- snip snip -->
<item name="android:actionBarStyle">#style/NewActionBar</item>
</style>
<style name="NewActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/text_pink</item> <!-- no effect -->
<item name="android:titleTextStyle">#style/NewActionBarTitle</item>
<item name="android:displayOptions">showHome|showTitle</item>
<item name="android:textAllCaps">true</item> <!-- no effect -->
</style>
<style name="NewActionBarTitle">
<item name="android:textSize">#dimen/tiny_text_size</item> <!-- no effect -->
<item name="android:textAllCaps">true</item> <!-- no effect -->
</style>
And why do the NewActionBar and NewActionBarTitle styles appear to have no effect no matter what I put in them? Is there something wrong with my styles or my action bar or what?
Edit: I've just deleted entirely the styles NewActionBar and NewActionBarTitle (and the reference to them in the AppTheme style) and the action bar looks completely the same. So something is broken. What could it be?
You need to set android:textAllCaps="true" on the text appearance for the action bar's title, rather than the action bar style itself or on your base activity theme.
<style name="AppTheme" parent="AppBaseTheme">
...
<item name="actionBarStyle">#style/Widget.MyApp.ActionBar.Solid</item>
</style>
<style name="Widget.MyApp.ActionBar.Solid"
parent="Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/TextAppearance.MyApp.Widget.ActionBar.Title</item>
</style>
<style name="TextAppearance.MyApp.Widget.ActionBar.Title"
parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textAllCaps">true</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
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>