我想,当用户选择在导航列表选择来更改操作栏背景的颜色。
目前,我的代码如下所示:
@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;
}
然而,我第一次在导航列表中选择itemPosition 1,它改变了动作条颜色为白色。
我第二次单击导航列表中itemPosition 1,我没有问题。
谁能告诉我这是为什么,我该如何解决这一问题? 感谢您的帮助!