Change actionbar background and title color - android

I am new to Android development. The app on which I am working requires white action bar background and the title should be black in color. I am using support library for lower compatibility.
Style.xml
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
How can I do this ?

Styles : Main App Theme
<style name="MyAppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/CustomActionBarStyle</item>
</style>
Setup styles for text and background color
<style name="CustomActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="background">#color/white</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
Setup TextColor Impt: parent must #style/TextAppearance.AppCompat.Widget.ActionBar.Title
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/action_bar_text_color</item>
</style>
For more refer links posted in #Santosh Shinde post

Use This to change title color
ActionBar actionBar = getActionBar();
actionBar.setTitle(Html
.fromHtml("<font color='#ffffff'> Now playing </font>"));
and for action bar title
getActionBar().setBackgroundDrawable(
new ColorDrawable(Color.rgb(0, 0, 0)));
or
getActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#000000")));

Try this style:
<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>
You can find more information here and here.

Related

How to change text color and background color of action bar items in android

I want to change text color and background color of action bar item which is white here. I searched alot but am not able to change this color.
Please check my code which I am using to customise action bar.
final ActionBar actionBar = getActionBar();
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor (Hexa color));
actionBar . setBackgroundDrawable (colorDrawable);
In your "res/values/themes.xml" file, do something like this:
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/MyPopupMenu</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<!-- Popup Menu Background Color styles -->
<style name="MyPopupMenu"
parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#color/Your_color_for_background</item>
</style>
<!-- Popup Menu Text Color styles -->
<style name="TextAppearance">
<item name="android:textColor">#color/Your_color_for_text</item>
</style>
And then in your manifest
<application
android:theme="#style/CustomActionBarTheme"
... >
Check this question and some of its answers for more clarification.
You can customize the action bar like below..
<!-- Base application theme. -->
<style name="Theme.AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/Theme.AppTheme.actionBar</item>
<item name="android:actionBarWidgetTheme">#style/Theme.AppTheme.actionBar.widget</item>
<item name="android:textViewStyle">#style/Theme.AppTheme.textView</item>
</style>
<!-- Actionbar things -->
<style name="Theme.AppTheme.actionBar" parent="android:Widget.Holo.Light.ActionBar.Solid">
<item name="android:titleTextStyle">#style/Theme.AppTheme.actionBarTitle</item>
<item name="android:subtitleTextStyle">#style/Theme.AppTheme.actionBarSubtitle</item>
<item name="android:background">#android:color/holo_blue_dark</item>
<item name="android:icon">#drawable/ic_launcher</item>
</style>
<style name="Theme.AppTheme.actionBarTitle" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
</style>
<style name="Theme.AppTheme.actionBarSubtitle" parent="android:TextAppearance.Holo.Widget.ActionBar.Subtitle">
<item name="android:textColor">#android:color/white</item>
</style>
<style name="Theme.AppTheme.actionBar.widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/Theme.AppTheme.actionBar.PopupMenu</item>
<item name="android:dropDownListViewStyle">#style/Theme.AppTheme.actionBar.DropDownListView</item>
</style>
<style name="Theme.AppTheme.actionBar.PopupMenu" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#android:color/holo_purple</item>
</style>
<style name="Theme.AppTheme.actionBar.DropDownListView" parent="#android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#android:color/holo_red_light</item>
</style>
<!-- Standard Widgets -->
<style name="Theme.AppTheme.textView" parent="android:Widget.TextView"></style>
Hope this will help you!

What is wrong with my Android style attributes, actionbar title hidden or no color?

I'm trying to customize ActionBar using styles.xml on KITKAT and older versions.
This is as far I got it, but missing actionbar title, no color inserted properly, height or what is wrong?
Here is my styles.xml
<style name="Theme.MyApp" parent="AppTheme">
<item name="actionBarStyle">#style/Theme.MyApp.ActionBar</item>
<item name="android:actionBarStyle">#style/Theme.MyApp.ActionBar</item>
</style>
<style name="Theme.MyApp.ActionBar" parent="style/Theme.MyApp">
<item name="elevation">4dp</item>
<item name="android:height">56dp</item>
<item name="android:textColor">#color/white</item>
<item name="android:icon">#drawable/icon_placeholder_compat</item>
<item name="android:background">#color/blue</item>
<item name="android:titleTextStyle">#style/Theme.MyApp.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/Theme.MyApp.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyApp.ActionBar.TitleTextStyle" parent="style/Theme.MyApp.ActionBar">
<item name="android:textColor">#color/white</item>
<item name="android:color">#color/white</item>
</style>
For change color of action bar and status bar:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/action_bar_color</item>
<item name="colorPrimaryDark">#color/status_bar_color</item>
</style>

Android ActionBar Background gets overridden by AppTheme Background

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>

White title background in ActionBar after changing the Actionbar Colour

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>

How do I change the style(color) of tabs in action bar v7 of android ?

I'm trying this to change the color and style of tabs in action bar using the v7 support library. But only the color of action bar is changed not the tabs. Please tell me what I'm doing wrong.
<!-- 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>
<item name="actionBarTabStyle">#style/TabStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Support library compatibility -->
<item name="background">#color/action_bar</item>
</style>
<style name="TabStyle"
parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="background">#drawable/tab_bar_background</item>
</style>
Try this (if you use actionbar tabs):
<style name="ActionBarTabs" parent="#style/Widget.AppCompat.Light.ActionBar.TabView.Inverse">
<item name="titleTextStyle">#style/ActionBarTitle</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="background">#drawable/tab_bar_background</item>
<item name="android:background">#drawable/tab_bar_background</item>
</style>
<style name="ActionBarTabBar" parent="#style/Widget.AppCompat.Light.ActionBar.TabBar.Inverse">
<item name="android:showDividers">middle</item>
<item name="android:divider">#drawable/list_divider_holo_light</item>
<item name="android:dividerPadding">8dp</item>
<item name="android:background">#color/actionbar_background</item>
</style>
<style name="TabTextStyle" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#android:color/black</item>
</style>
and in your theme:
<style name="AppTheme" parent="#style/AppBaseTheme">
...
<item name="android:actionBarTabStyle">#style/ActionBarTabs</item>
<item name="actionBarTabStyle">#style/ActionBarTabs</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionBarTabBarStyle">#style/ActionBarTabBar</item>
<item name="actionBarTabBarStyle">#style/ActionBarTabBar</item>
...
</style>
If you want to change the color of the menu items in the action bar you have to set the actionMenuTextColor in your theme style.
<style name="PortfolioTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionMenuTextColor">#24598a</item>
<item name="actionMenuTextColor">#24598a</item>
</style>
To customise tabs color, I suppose you should change your TabStyle item to be :
<item name="android:actionBarTabBarStyle">#style/TabStyle</item>
override "android:actionBarTabBarStyle" rather than "android:actionBarTabStyle"

Categories

Resources