In default, android using the Theme.AppCompat.Light.DarkActionBar theme and the status bar text is white, how to change it to black?
actually you could change the color of statusbar for Api >= 19
inside the style of value-v19 put :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="MaterialDrawerTheme.Light">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
.....
</style>
</resources>
Thanks #mohosyny for advising to introduce the material theme, I fix my problem by using the below AppTheme.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
</style>
</resources>
Related
I'm trying to change the colors of my StatusBar, when I try to alterate the colorPrimaryDark (first bar, where stays batery, tima, date, etc...) the color do not change.
I've created a xml with the values of the colors that I use
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name = "primary">#162d50</color>
<color name = "primary_dark">#010101</color>
<color name = "textprimary">#FFFFFF</color>
</resources>
And my styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:textColorPrimary">#color/textprimary</item>
</style>
</resources>
In other words, I can change colors of my background, titlebar, text, but when I try to change colorPrimaryDark, no matter what the value entered the color never change, could someone help me please?
Change your theme to this.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Remove android tag and try it again.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="textColorPrimary">#color/textprimary</item>
</style>
</resources>
There are various ways to change color of status bar. Below is my solution.
Edit your style.xml as below. You can directly add android:statusBarColor tag to your xml.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#d9591b</item>
</style>
Note -: android:statusBarColor is available in minsdk version 21. It will not work below api level 21. You need to modify your gradle file. Change minSdkVersion to 21.
Edit Your Style.Xml and add this within the resources tags:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colortoolbar</item>
<item name="colorPrimaryDark">#color/colortoolbar</item>
<item name="colorAccent">#color/colortoolbar</item>
</style>
where colortoolbar is already defined in my colors.xml. You can define your own color.
My ActionMode menu is showing up as plain white and I don't know why.
I have an ActionMode menu.xml which simply has a delete option:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_delete"
android:title="Delete"
android:icon="#android:drawable/ic_menu_delete"/>
</menu>
and I have a theme applied to my whole app, defined in styles.xml:
<resources>
<!-- Base application theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/paletteLightBlue3</item>
<item name="colorPrimaryDark">#color/dark_grey</item>
<item name="colorAccent">#color/paletteLightBlue</item>
<item name="android:actionModeStyle">#style/aModeBg</item>
</style>
<style name="aModeBg" parent="#style/Widget.AppCompat.ActionMode">
<item name="android:actionModeBackground">#color/dark_red</item>
</style>
</resources>
As you can see, I've tried setting the actionModeBackground property to dark red, but it still just shows up as white. Can anyone help? Thanks.
OK so I solved this by simply doing this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/paletteLightBlue3</item>
<item name="colorPrimaryDark">#color/dark_grey</item>
<item name="colorAccent">#color/paletteLightBlue</item>
<item name="android:actionModeBackground">#color/dark_red</item>
</style>
I just put set the actionModeBackground in my AppTheme, instead of a separate style. Simple.
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>
I add following code, but it is for API level 14
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
Please help me to find the solution.
<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>
</style>
</resources>
Taken from Android developer site.
You need to basically use the colorPrimary value to denote Action Bar color. There are others as well to show status bar color and all, which you can find in the link.
This is what I have used to do the job, but I was using AppCompat.
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="CustomActionBarTheme" parent="#style/AppTheme">
<item name="actionBarStyle">#style/CustomActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="CustomActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/actionbar_foreground</item>
</style>
And make a drawable called actionbar_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF0000"/>
</shape>
Don't forget to update AndroidManifest.xml
<application
android:theme="#style/CustomActionBarTheme">
ToolBar.setBackgroundColor(Color.BLACK);
It works for me in API 21:
if you use AppCompatActivity
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.<YOUR_COLOR>)));
I've included my theme in the Manifest file. My theme's code is as follows
<resources>
<!-- Activity themes -->
<style name="Theme.Base" parent="Theme.AppCompat.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<style name="AppTheme" parent="Theme.Sample" >
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/blue</item>
</style>
</resources>
All my activities inherit ActionBarActivity
I can't seem to change the color of my ActionBar.
Please help.
I am running this on an emulator with API 21.
How can I style my ActionBar?
The AppCompat v21 doesn't read any android: attributes related to the action bar:
<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>
You can change the color adding this code to your style:
<item name="colorPrimary">#android:color/holo_red_dark</item>
With colorPrimaryDark you can change the status bar color.
Take care, use colorPrimary, dont use android:colorPrimary, this last only works with 21.
All code:
<resources>
<!-- Activity themes -->
<style name="Theme.Base" parent="Theme.AppCompat.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<style name="AppTheme" parent="Theme.Sample" >
<item name="colorPrimary">#android:color/holo_red_dark</item>
</style>
</resources>
I found this Google Blog Post for the v21 appCompat extremly helpful. It explains the usage pretty good.
You can do this by below way
Simply edit the res/values/styles.xml file of your Android project.
For example like this:
<resources>
<style name="MyCustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
or by java code
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED));