Changing Android App Background Including Spinners and Dialogs - android

I want to change default white background in my android app to another color.
I am using android:background="#HEXCODE" in my activity, it changes the background but the dialogs and spinners still have white background.
I also tried creating styles / custom theme but it changes the entire theme (the button and spinner style look like Androind 2.3 instead of ICS look and feel)
I don't want to change anything but on the background that is consistent also in spinners and dialogs.
Thanks.
EDIT
Style Code:
<style name="MyTheme" parent="android:Theme.Light">
<item name="android:background">#FFFFBB</item>
</style>
Manifest:
android:theme="#style/MyTheme"

Try setting the color of the backgrounds of all widgets and the layout by
android:background="#color/black">
in your values folder make a xml like this
<resources>
<color name="red">#ff0000</color>
<color name="green">#00ff00</color>
<color name="blue">#0000ff</color>
<color name="black">#000000</color>
</resources>
This worked for me.

Related

colorPrimary or primaryColor?

Everywhere on the web I see uses of colorPrimary until I stumbled across Google's very own Color Tool where they use:
-<resources>
<color name="primaryColor">#303f9f</color>
<color name="primaryLightColor">#666ad1</color>
<color name="primaryDarkColor">#001970</color>
<color name="secondaryColor">#fdd835</color>
<color name="secondaryLightColor">#ffff6b</color>
<color name="secondaryDarkColor">#c6a700</color>
<color name="primaryTextColor">#ffffff</color>
<color name="secondaryTextColor">#000000</color>
</resources>
Once you export your picks.
So what is the correct convention? Also, would it affect the Material Components colors of widgets?
1.If you define a color in res/values/colors.xml, then you can use any name on your own, the same when you create a variable in your Java/Kotlin class.
primaryColor
colorPrimary
primary_color
color_primary
An example from Android Developer
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="opaque_red">#f00</color>
<color name="translucent_red">#80ff0000</color>
</resources>
2.If you create a custom styles/themes which extends from Android styles/themes, then you must use name that defined by Android.
// colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primaryColor">#008577</color>
<color name="primary_dark_color">#00574B</color>
<color name="color_accent">#D81B60</color>
</resources>
// styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primary_dark_color</item>
<item name="colorAccent">#color/color_accent</item>
</style>
As you can see, in styles.xml, 3 attribute names, colorPrimary, colorPrimaryDark, colorAccent has been defined in parent theme, so you must use the same name because you want to override it.
In colors.xml, you can use any name that you think it make sense in your app.
Back to your questions:
So what is the correct convention?
There is no standard convention in this case, but from Android Developer, you just give a name for the color, no need to add color/Color as a prefix or suffix. Because we usually put all app's colors in res/values/colors.xml, and each item is inside a color tag.
Would it affect the Material Components colors of widgets?
It does not.
They are not the same, check out
Themes versus Styles

Multiple themes changing tab icon color

I have been learning MDC from google code lab, and it is a well designed application to know how material design works. However, in a particular section they showed how to use dark theme. The did it by changing the theme attributes from style.xml. Being resourceful, I have been trying to learn how to use multiple theme and interchange them runtime.
For this reason I avoided their hard-coded way and tried to inherit the base theme and put changes according to my need. Below I am putting some changes in the theme file
<!--Dark Theme style !-->
<style name="Theme.Shrine.Dark" parent="Theme.Shrine">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/darkColorPrimaryDark</item>
<item name="colorPrimaryDark">#color/darkColorPrimaryDark</item>
<item name="colorAccent">#color/darkColorAccent</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:textColorPrimary">#color/darkTextColorPrimary</item>
<item name="colorControlActivated">#color/darkColorControlActivated</item>
<item name="toolBarStyle">#style/Widget.Shrine.Toolbar.Dark</item>
<item name="appBackGroundColor">#color/darkBackgroundColor</item>
</style>
There are some changes but they are irreverent to my problem, so I am not going to add them here. Anyway, with changes in my style file app looks something like this
Everything is expected except for icon colour in toolbar. So I check into the code and find every icon colour is referenced from the their respective from drawable file with android:tint="#color/toolbarIconColor" and in color.xml toolbarcolor is <color name="toolbarIconColor">#color/textColorPrimary</color>
It shows wrong color in dark mode, in this case how can I show yellow color in dark mode. I have changed textColoeSecondary from base theme of dark theme but it didn't work
Firstly, you need to remove hard reference of colour from every drawables which reflect different colours depending on app theme. So, add attrs.xml in your values directory. and add the reference name for icon colour such as this one
<attr name="toolbarIconColor" format="reference"/>
Secondly, add two different colour for two themes. For example, for normal theme <color name="toolbarIconColor">#color/textColorPrimary</color> and for dark one use <color name="darkToolbarIconColor">#FFCF44</color>
Finally, go to your style.xml file and make this change to hook up with the reference we have added in attrs.xml file, like this one for normal theme <item name="toolbarIconColor">#color/toolbarIconColor</item> and <item name="toolbarIconColor">#color/darkToolbarIconColor</item>

Changing color of Ripple Effect

I got a ListView where the background is black. Now my problem is that the default ripple effect is also black is the user cant really see it.
How can I change the color of the Ripple Effect without be dependent on API level ? (I want to achieve a white color).
You can set this as your views background:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorAccent">
<item android:id="#android:id/mask">
<color android:color="#42ffffff" />
</item>
For more details see this question on stackoverflow:
What should be the color of the Ripple, colorPrimary or colorAccent? (Material Design)
And you can use this library for lower apis:
https://github.com/traex/RippleEffect
Simply way to do is define these two colors inside your colors.xml file
<color name="ripple_material_dark">#33ffffff</color>
<color name="ripple_material_light">#1f000000</color>
cheers.
Just add 'item: colorControlHighlight' with the desired color in your styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlHighlight">#color/white</item>
</style>
When using Theme.MaterialComponents.* theme the ripple color can be defined by
adding following line to i.e. Ouline Button style.
<item name="rippleColor">#color/outline_button_ripple_color</item>

Changing color themes in Android Studio

I am trying to change the color of my Hello World app.
Right now it looks like this in the emulator (purple bar, pink floating icon):
But when I change the theme setting, I get a bunch of rendering errors (note that I tried to choose Material Light):
And when I try to run the app again it still looks purple/pink as it did in the first pic. I'm not really sure how to make heads or tails of these kinds of errors or how I am supposed to fix them.
You are changing the theme of the preview window. This is used to view how your layout would look using a given theme. It does not change the theming on your phone when running your app—it is just a preview.
To actually change the colors you need to change the theme. Usually this would be the AppTheme that is referencing some colors.
Locate your colors.xml in res/values/ and modify the colors there:
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
These colors get used by the theme generated at project creation, looking like this in styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
You could also remove the reference and edit the colors in the theme directly, but that is usually not the clean way. Your styles.xml would also be the right place to add more themes—which in turn you could preview in Android Studio.

How to change AutoCompleteTextView border color of default theme in android?

I am using AutoCompleteTextView in my android application. I am using Theme.Light as my default theme for my application.
Here is how my AutoCompleteTextView look like
Now, I want to change the BLUE color border of that AutoCompleteTextView to some other color ,for different selection, keeping the border style as it as. I dont want full border. How to do that?
You can try like this..
see http://www.androidworks.com/changing-the-android-edittext-ui-widget for details
For other theme implementation go for this way
In your manifest in application
android:theme="#style/firsttheme"
IN res/values you can define theme.xml
<resources>
<style name="firsttheme" parent="#android:style/Theme" >
<item name="android:_DEFAULT_BASE_COLOR_1">#XXXXXX</item>
<item name="android:windowNoTitle">true</item>
... .
</style>
</resources>
For more info theme
You can use Holo Colors to tint it. It generates the 9-patchs and the styles.

Categories

Resources