I want to change the background color of the action bar when the user selects a selection from the navigation list.
Currently, my code looks like this:
@Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { ColorDrawable colorDrawable = new ColorDrawable(); ActionBar actionBar = getActionBar(); if(itemPosition == 0) { colorDrawable.setColor(0xffFEBB31); actionBar.setBackgroundDrawable(colorDrawable); return true; } if(itemPosition == 1) { colorDrawable.setColor(0xff9ACC00); actionBar.setBackgroundDrawable(colorDrawable); return true; } return false; }
However, the first time I select itemPosition 1 in the navigation list, it changes the color of the ActionBar to white.

The second time I click itemPosition 1 in the navigation list, I have no problem.

Can someone tell me why this is so and how can I solve the problem? Thanks for the help!
source share