ActionBar and ActionBar Tabs are pure white - android

How can we make action bar and action bar tabs pure white. I am using android-support-v7-appcompat libs to support backward compatibility. style/Theme.AppCompat.Light.DarkActionBar gives pure black but style/Theme.AppCompat.Light does not give pure white.

There is no default theme that would give a white action bar. You will need to make a customized action bar for your app.
The developer docs has a good article about customizing the action bar.
https://developer.android.com/training/basics/actionbar/styling.html
These are the custom styles that you will need to alter.
res/values/themes.xml
See the android:background tag where you can set a drawable for the action bar.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
</style>
</resources>
Apply the theme to your app.
<application android:theme="#style/CustomActionBarTheme" ... />

Related

android: how to modify the font-color of status bar

how to modify the font-color of status bar?
I find that some android applications can modify the font-color of status bar.I don't know how to do it.
Following are two pictures help to describe the question.Thanks!
the one after I open the application
the one before I open the application
The font-color of the one is white, while the other one is black.
Thanks to the release of Material Design you are able to change the color of status bar.
First of all you have to tell your app to use material design through your manifest (you can use a material theme of your choice):
android:theme="#android:style/Theme.Material.Light"
To use material design your minSDK of your app have to be 21 (Lollipop) or alternatively you can use the v7 Support Libraries for the previous versions.
https://developer.android.com/tools/support-library/features.html#v7
Now, there are to ways to set the color of the Status bar.
First, change it through the activity dynamically with the color you want every time (You have to declare color "blue" to your resources) - Inside you activity type:
getWindow().setStatusBarColor(getResources().getColor(R.color.blue));
And the second one is to extend the material design through your resources xml:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/accent</item>
<!-- USE THIS FOR STATUS BAR COLOR -->
<item name="android:statusBarColor">#color/blue</item>
</style>
</resources>
https://developer.android.com/training/material/theme.html#ColorPalette
For a quick test please use option one, hope i helped you!
Try this.
Put this line in your dependency structure of gradle.
compile "com.android.support:appcompat-v7:21.0.+"
In your values/themes.xml
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Here we setting appcompat’s actionBarStyle -->
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">#color/my_awesome_red</item>
<item name="colorPrimaryDark">#color/my_awesome_darker_red</item>
<!-- The rest of your attributes -->
</style>
For further details:-https://chris.banes.me/2014/10/17/appcompat-v21/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(R.color.your_color);
}

how to change actionbar's menu item text color in material design

I'm trying to update my notepad app to use Material Design, even on older devices.
What i did so far:
add library appcompat_v7 to my project, to support Material Design on older devices
modify theme in AndroidManifest, adding android:theme="#style/Theme.NoteItTheme" to <application ... ></application> attributes
creating the theme in /res/values/themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.NoteItTheme" parent="Theme.AppCompat.Light">
<!-- Here we setting appcompat’s actionBarStyle -->
<!-- <item name="actionBarStyle">#style/MyActionBarStyle</item> -->
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="android:textColorPrimary">#color/text</item>
<item name="colorAccent">#color/ui</item>
<!-- The rest of your attributes -->
</style>
The problem:
As you can better see here:
when i expand the actionbar's menu, text color and background color are very similar.
I hadn't this problem before, how do i change just the items text color?
<item name="android:textColorPrimary">yourColor</item>
Above code changes the text color of the menu action items for API >= v21.
<item name="actionMenuTextColor">#android:color/holo_green_light</item>
Above is the code for API < v21
Some tutorials:
Changing toolbar's text color and overflow icon color
Appcompat v21 Pre-Lollipop devices
Below worked for me
<item name="actionMenuTextColor">yourColor</item>
<item name="android:actionMenuTextColor">yourColor</item>
Below work for me fine.
<item name="android:textColor">your color</item>

Styling Actionbar Appcompat devider

I am working on an app where I have to modify the app Actionbar. I am able to design it according to the requirement, but facing problem in designing the white line beneath the action bar. Well, I have got some hack where I can take the view and design it. But I want it to style it using style.xml.
EDIT
Now google has released toolbar that you can modify easily.
You can style your action bar like the below code -
<?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>
and also please check the link - https://developer.android.com/training/basics/actionbar/styling.html to get more information. Hope it helped you.

Styling the action bar compatibility

I copied this extract directly from the android online documentation Styling the Action Bar
For Android 3.0 and higher only
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>
My minSdk is 11 and yet I'm receiving compatibility warnings at the parent tag. Why?
Theme.Holo.Light.DarkActionBar is only 4.0+, that's why you get the warning. To fix that you can use Holo Light, or change the theme according the the Android version (so you'll have light on Honeycomb and Light with dark actionbar on ICS+).

Custom theme for a dark actionbar / tab bar

I am trying to set a custom actionbar for my app like so
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
<item name="android:actionMenuTextColor">#FFFFFF</item>
<item name="android:actionBarWidgetTheme">#style/MyActionWidgetTheme</item>
<item name="android:actionBarStyle">#style/BasicActionBar</item>
</style>
<style name="BasicActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#color/red</item>
</style>
when i don't include
<item name="android:actionBarStyle">#style/BasicActionBar</item>
The actionbar and tab bar appear dark but i want to set the actionbar's color and keep the tabs dark. When i set the style the action bar changes color but the tabs turn to white.
I am pretty sure the problem is
parent="android:Widget.Holo.ActionBar"
I have tried any bunch of different possible values for this but can't find one that keeps the tab bar dark
this link helped me http://jgilfelt.github.io/android-actionbarstylegenerator/
#style/Widget.Sherlock.Light.ActionBar.Solid.Inverse
did the trick

Categories

Resources