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.
Related
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>
I want to change the whole app color at run time. When I start my app, I have to hit an api which returns me a RGB color value and I have to change whole app color accordingly. Any idea?
Something like this maybe?
ThemeColors.setNewThemeColor(MainActivity.this, red, green, blue);
Set your colors value in res/values/colors.xml
Example:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
then
Set your styles in res/values/styles.xml
Example:
<resources>
<!-- 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="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
At run-time it will use these settings.
I'm trying to learn Android, now I'm trying to change color in my android project. Here is what I do,
I change my color.xml to:
<resources>
<color name="primaryColor">#d81b60</color>
<color name="primaryLightColor">#ff5c8d</color>
<color name="primaryDarkColor">#a00037</color>
<color name="primaryTextColor">#ffffff</color>
</resources>
and my style.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="primaryColor">#color/primaryColor</item>
<item name="primaryLightColor">#color/primaryLightColor</item>
<item name="primaryDarkColor">#color/primaryDarkColor</item>
<item name="primaryTextColor">#color/primaryTextColor</item>
</style>
But when I try to run I get this error(s):
So, how can I fix it?
I already try this:
Android Studio does not find color style resource
Android Studio can't find color reference within the same resource file
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
in style these tags are used to specify the colorPrimary accent and primaryDark
to be more specific change the style xml as
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryDarkColor</item>
<item name="colorAccent">#color/primaryAcentColor</item>
</style>
Here you go..
You need to create attrs.xml under values folder.
Mention all your reference colors inside this file.
e.g.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="primaryColor"></attr>
<attr name="primaryLightColor"></attr>
<attr name="primaryDarkColor"></attr>
<attr name="primaryTextColor"></attr>
</resources>
Now you can directly use your colors in style.xml
e.g.
<resources xmlns:android="http://schemas.android.com/tools">
<!-- 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="primaryColor">#color/primaryColor</item>
<item name="primaryLightColor">#color/primaryLightColor</item>
<item name="primaryDarkColor">#color/primaryDarkColor</item>
<item name="primaryTextColor">#color/primaryTextColor</item>
</style>
</resources>
You are trying to define non-exist attribute in your style:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="primaryColor">#color/primaryColor</item>
<item name="primaryLightColor">#color/primaryLightColor</item>
<item name="primaryDarkColor">#color/primaryDarkColor</item>
<item name="primaryTextColor">#color/primaryTextColor</item>
</style>
There are no primaryColor, primaryLightColor, primaryDarkColor, and primaryTextColor. The right attributes are colorPrimary, colorPrimaryDark, colorPrimaryLight, and textColorPrimary. This image will show you the attributes (from Using the material theme):
So, you need to change it to the following:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryLight">#color/primaryLightColor</item>
<item name="colorPrimaryDark">#color/primaryDarkColor</item>
<item name="textColorPrimary">#color/primaryTextColor</item>
</style>
I've used inbuilt theme Theme.AppCompat.NoActionBar for my app. But it gives complete black background. I want to change this black background to gray one. So I tried to customize my theme as following:
Here is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="MyTheme"> // Using Customized theme.
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
//Customize the Theme.
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:backgroundDimAmount">0.8</item>
</style>
Here I want to lighten my background color so I'm using android:backgroundDimAmount but it is not working.
I've also used following:
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#707070</item>
</style>
This changes the background color, but gives me weird results as following screen shot:
Where as My actual activity looks like following screen shot:
So my question how can I lighten or possibly change the background color?
you want this
<item name="android:background">#color/<mycolor></item>
<item name="android:windowBackground">#color/<mycolor></item>
<item name="android:colorBackground">#color/<mycolor></item>
remember to change it in all styles xmls
you should use style as this in style.xml.....
<resources>
<!-- 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:background">#color/gray</item>
<item name="android:windowBackground">#color/gray</item>
<item name="android:colorBackground">#color/gray</item>
</style>
</resources>
and in colors.xml make this.....
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="gray">#707070</color><!--this your color-->
</resources>
the final out put
Replace android:background to android:windowBackground.
Also change the hardcoded color (e.g #707070) to color reference (e.g #color/myYellowBackgroundColor) .
When using android:windowBackground you tell android to affect background of child's view only inside the main activity on the screen.
use this in your styles.xml file
<item name="android:statusBarColor">#color/yourcolor</item>
remember to add your color in color.xml file. don't hardcode your 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.