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?
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With