Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change values of colors.xml to change look and feel of android app

Problem : I am trying to change the look and feel of my Android app, on the fly. Something like, the app starts up and gets a set of values from the server. These values are the elements that typically go inside colors.xml. What I am looking for, is a way to dynamically change the elements inside the colors.xml and update it with these new values received from the server. My understanding is that normally, this cannot be done directly. But has anyone found a workaround?

What I want to avoid if possible : I would like to avoid setting color values inside each activity's onCreate() method for each element in that view. If at all possible, I would like to avoid this.

Any thoughts?

like image 272
Rohitesh Avatar asked Dec 12 '16 09:12

Rohitesh


People also ask

How do I color in XML?

To edit text color you need to follow the next steps: 1) Open XML file and locate the text you need to change color. 2) Add <font color="color_value"> before text, and </font> after text. You should use closing </font> tag after the text you need to change color, it is very important.


2 Answers

Unfortunately all color values (and other resources) inside the resources directory are hardcoded as static final ints. This means there is no way to change the values at runtime. You can however use one of the previously suggested solutions or have a look at this excellent explanation: https://stackoverflow.com/a/33992017/3662251

For a nice workaround that overrides the activity's getResources method and implements a custom Resources class which is in my opinion the most seamless solution: https://stackoverflow.com/a/34178187/3662251

like image 167
code_mc Avatar answered Oct 17 '22 22:10

code_mc


You can achive this change by newly introduce firebase remote config which provide remote config to change theme color or any other values necessary for app like promotion,updates etc

You can refer this Example

like image 36
Burhanuddin Rashid Avatar answered Oct 17 '22 20:10

Burhanuddin Rashid