Android: Changing the colour of the action bar - android

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));

Related

Changing the colour of actionbar hides the settings button

I tried to change the colour of actionbar by making few changes in default theme.
But the problem is when the colour changes, it hides the settings button.please suggest me the changes.
Heres the xml file for styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorWhite</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
You can add the android:textColorSecondary attribute to your theme.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
.....
<!-- color of the menu overflow icon -->
<item name="android:textColorSecondary">#color/my_color</item>
</style>
Otherwise, since you are using a white Toolbar, you can use override the theme with:
<android.support.v7.widget.Toolbar
app:theme="#style/ThemeToolbar" />
with:
<style name="ThemeToolbar" parent="Theme.AppCompat.Light">
<!-- navigation icon color -->
<item name="colorControlNormal">#color/my_color</item>
<!-- color of the menu overflow icon -->
<item name="android:textColorSecondary">#color/my_color</item>
</style>

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>

how to change actionbar color using AppCompactActivity?

I'm trying to make the action bar color in blue but always is black, I'm using to files for styles : styles.xml and styles-21.xml.
This the code in styles-21.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/blue_color_500</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/blue_color_900</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/purple_color_200</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="#android:background">#color/blue_color_500</item>
<item name="background">#color/blue_color_500</item>
</style>
and this is the style for styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- Customize your theme here. -->
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/blue_color_500</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/blue_color_900</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/purple_color_200</item>
<item name="android:windowBackground">#color/blue_color_50</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/blue_color_500</item>
<item name="background">#color/blue_color_500</item>
</style>
My class inheritance from AppCompatActivity...
Any help with that?
Thank you in advance.
Check this link from official android docs. You should use not only android:actionBarStyle but actionBarStyle too while using compatibility lib.
Here is a way to change the color of your Action Bar :
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/mainColor</item>
<item name="colorPrimaryDark">#color/mainColorDark</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarWidgetTheme">#style/ActionBarWidget</item>
</style>
<style name="Widget.MyApp.ActionBar" parent="AppTheme">
<item name="theme">#style/ThemeOverlay.MyApp.ActionBar</item>
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
</style>
<style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#color/white</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/mainColor</item>
</style>
<style name="ActionBarWidget" parent="Theme.AppCompat.Light.DarkActionBar"/>
<color name="mainColor">#E41F26</color>
The Action Bar will be colored with mainColor defined at the end ! I Hope it will help
Thank you very much, you were right this is the code fix it:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- Customize your theme here. -->
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/blue_color_500</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/blue_color_900</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/purple_color_200</item>
<item name="android:windowBackground">#color/blue_color_50</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/blue_color_500</item>
<item name="background">#color/blue_color_500</item>
</style>

set text color of Appcompat action bar does not work

Basically I followed this guide about customizing the Action bar https://developer.android.com/training/basics/actionbar/styling.html
and have this style in my styles.xml
<style name="Blue" parent="Theme.AppCompat">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/light_blue</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/dark_blue</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#color/light_blue</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/white</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/white</item>
</style>
with this custom action bar to change title text to white
<!-- 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>
<item name="android:subtitleTextStyle">#style/MyActionBarSubtitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
<item name="textColor">#color/white</item>
</style>
<!-- ActionBar subtitle text -->
<style name="MyActionBarSubtitleText"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">10sp</item>
<!-- The textColor property is backward compatible with the Support Library -->
<item name="textColor">#color/white</item>
<item name="textSize">10sp</item>
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/white</item>
<item name="textColor">#color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
but apparently the text and icon color remains black. Am I missing something?
If you just want the text to be white, that is the default for Theme.AppCompat or, if you want a light activity, use Theme.AppCompat.Light.DarkActionBar

want action bar becomes transparent but becomes grey

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

Categories

Resources