當用戶在導航列表中選擇一個選擇時,我想更改操作欄背景的顏色。從導航列表中更改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;
}
但是,我第一次在導航列表中選擇itemPosition 1,它改變了動作條顏色爲白色。
第二次單擊導航列表中的itemPosition 1時,我沒有問題。
有誰能告訴我爲什麼這是,我該如何解決這個問題?感謝您的幫助!
你有沒有解決這個問題? – 2013-05-07 12:57:17