title: Change Background Color of AppCompat Action Bar
body: <p>I am in a fragment and I want to change the actionbar color and view background color when the user clicks on a button.  The code I currently have below causes the action bar to go gray no matter what color the user chooses.</p>
  
  <pre><code>private void changeColor( int colorId ) {
      ActionBar actionBar =  ((ActionBarActivity )getActivity()).getSupportActionBar();
      actionBar.setBackgroundDrawable( new ColorDrawable( colorId ) );
      this.getView().setBackgroundColor( getResources().getColor( colorId ) );
  }
  </code></pre>
  
  <p>I have the actionbar themed to be blue in my styles.xml not sure if that has any effect.  If you have any suggestion please let me know.  </p>
  
  <p>Thanks,
  Nathan</p>
  
  <p>Solution:
  Had to change:</p>
  
  <pre><code>actionBar.setBackgroundDrawable( new ColorDrawable( colorId ) );
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>actionBar.setBackgroundDrawable( new ColorDrawable( getResources().getColor( colorId ) ) );
  </code></pre>