title: Programmatically change the value of a color resource obtained from API response
body: <p>Let's say, on my API call I have a parameter that's called <code>color</code>. Is it possible to edit or modify an existent <code>R.colors.color</code> to assign the color from the API result?</p>
  
  <p>As an example:</p>
  
  <p>I make a call to my API and it returns <code>green</code>, now I want to load my app with i.e (green <code>Toolbar</code>, green <code>TextView</code> color, etc.), is that possible?</p>
  
  <p>My first thought was: </p>
  
  <p>Create a item on <code>colors.xml</code> called <code>demo</code> then assign it a default color, then use this <code>demo</code> color wherever I want (<code>Button</code>, <code>TextView</code>, etc.) Then I thought it could be possible to change this value programmatically with the result from the API so I wouldn't need to create a <code>SharedPreferences</code> or something like that and for avoiding more code.</p>
  
  <p>As <a href="https://stackoverflow.com/users/3287204/y-s">@Y.S.</a> said to me </p>
  
  <blockquote>
    <p>Unfortunately, you WILL have to set the color of the text or view manually everywhere ... :( </p>
  </blockquote>
  
  <p>I would like if there is other way to do it, since I don't know how many <code>Activities</code> my project will contain, so if is there other way to do it I'm glad to hear other guesses.</p>
  
  <h2>EDIT</h2>
  
  <p>I'm trying the @Jared Rummler answer and maybe i'm doing something wrong... I've created a simple <code>Json</code> and I put on my Assets I parse the <code>Json</code> and I put it on a <code>GlobalConstant</code> then I made a "simple app".</p>
  
  <p>First of all I have a <code>TextView</code> and a <code>Button</code> which contains the "your_special_color", and the return of it I put the <code>GlobalConstant int</code> as follows : </p>
  
  <pre><code>case "your_special_color":                
              return GlobalConstant.color; 
  </code></pre>
  
  <p>Then what I tried is my first <code>Activity</code> has 1 <code>TextView</code> and 1 <code>Button</code> as I said before and they have the color "your_special_color" that I don't want to change it, BUT I have an <code>Intent</code> on my <code>Button</code> to open the other <code>Activity</code> that contains the same but with the <code>GlobalConstant.color</code> and it doesn't change.</p>
  
  <p>I tried it doing this (my second Activity):</p>
  
  <pre><code>public class Main2Activity extends AppCompatActivity {
  private Res res;
  @Override public Resources getResources() {
      if (res == null) {
          res = new Res(super.getResources());
      }
      return res;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main2);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  }
  </code></pre>
  
  <p>Did I miss something?</p>
  
  <p>Oh.. I figured it out I guess is doing this on my <code>MainActivity2</code> ? </p>
  
  <pre><code> Button btn = (Button)findViewById(R.id.button2);
   btn.setBackgroundColor(res.getColor(R.color.your_special_color));
  </code></pre>