This will help if you described why and how you use this dynamic color, and why you want to do this at runtime instead of build time. But assuming this should be as you requested ...
I suggest writing a helper function that all places can call and set.
public int getMyColor(...) {
Now call this for each required action / fragment and set the color attributes (a) in the respective views as necessary. (With View.setBackgroundColor(...) etc.)
However, to allow this to work in the XML preferences and layout preview, you need to write your own view class to call this helper function. Depending on where and how you use this color, it may not be worth it.
This solution is not very elegant and requires a lot of calling this custom helper function getMyColor in every action / fragment that it needs. If it is installed in only one or two places, this probably does not matter much. Again, knowing why you want to do this, and not ask us how to do this, may give you a better alternative.
For example, this is not the answer to your question, but have you thought about that? It will still have a problem installing them during the build, if you do not want all of the above, but depending on how you use this color, it may be better than the mess described above.
source share