Tyk*_*kin 5 android android-actionbar
我想在用户选择导航列表中的选择时更改操作栏背景的颜色.
目前,我的代码如下所示:
@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;
}
Run Code Online (Sandbox Code Playgroud)
但是,第一次在导航列表中选择itemPosition 1时,它会将ActionBar颜色更改为白色.

第二次单击导航列表中的itemPosition 1时,我没有问题.

谁能告诉我为什么会这样,以及如何解决问题?感谢您的帮助!
小智 10
尝试使用此代码:
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#ffFEBB31"));
actionBar.setBackgroundDrawable(colorDrawable);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21044 次 |
| 最近记录: |