title: Change ActionBar Background Color Dynamically
body: <p>I would like to know is it possible to change <a href="http://developer.android.com/reference/android/app/ActionBar.html" rel="noreferrer"><code>ActionBar</code></a> (in <a href="http://developer.android.com/tools/support-library/index.html" rel="noreferrer">Support Library</a>) Background Color dynamically according to selected page in viewpager or selected actionbar tabs. I have tried with the following code. But, it doesn't work. Please help.</p>
  
  <pre><code>mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
  
      @Override
  
      public void onPageSelected(int position) {
  
          actionBar.setSelectedNavigationItem(position);    
  
          if(position == 0){
              actionBar.setBackgroundDrawable(new ColorDrawable(Color.GREEN));
          }else if(position == 1){
              actionBar.setBackgroundDrawable(new ColorDrawable(Color.BLUE));
          }else{
              actionBar.setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
          }
  
      }
  });
  </code></pre>