I have a theme defined in .xml file and applied to the application tag in Manifest file. I also have a hex value of color stored in SharedPreferences. Is there any way to set this color as a theme's background?
Asked
Active
Viewed 1,064 times
2 Answers
1
You can change the background color of your window or Activity and the color value can come from your SharedPreferences value using setBackgroundColor.
If it is the Activity window that you want the background color changed, you can do the following:
getWindow().getDecorView().setBackgroundColor(getResources().getColor(android.R.color.holo_red_light));
Just replace the android.R.color.holo_red_light with the value from your XML file.

Christian Abella
- 5,747
- 2
- 30
- 42
0
You cannot alter the theme as it is already "compiled", but you can switch between them. For that you can check HERE

Community
- 1
- 1

Bojan Kseneman
- 15,488
- 2
- 54
- 59
-
The problem is that i get the color value dynamically from user so it can't be defined before. – graczultima Apr 21 '15 at 22:39
-
if you are doing so, you may need to make your original theme transparent, since it is drawn prior to your onCreate call and you will see a change in colors from original theme to your color. No the most user friendly. – Bojan Kseneman Apr 22 '15 at 15:44