2013-04-03 40 views
1

我正在使用Sherlock庫的Actionbar上工作。我想以不同的方式更改操作欄和製表符的背景圖像。目前我已經通過代碼在運行時成功地更改了動作條的背景:更改Android中Sherlocks庫中ActionBar中Tabs的背景顏色?

Drawable myIcon = getResources().getDrawable(R.drawable.blue_menu_background); 
mActionBar.setBackgroundDrawable(myIcon); 

但是我遇到了Tab背景問題。我如何更改選項卡的背景。請建議我。

回答

2

而是這樣做的,你可以使用樣式標籤:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <!-- the theme applied to the application or activity --> 
    <style name="CustomActivityTheme" parent="@android:style/Theme.Holo"> 
     <item name="android:actionBarTabTextStyle">@style/CustomTabTextStyle</item> 
     <item name="android:actionBarDivider">@drawable/ab_divider</item> 
     <item name="android:actionBarItemBackground">@drawable/ab_item_background</item> 
    </style> 

    <!-- style for the action bar tab text --> 
    <style name="CustomTabTextStyle" parent="@android:style/TextAppearance.Holo"> 
     <item name="android:textColor">#2456c2</item> 
    </style> 
</resources> 

檢查這個article瞭解更多詳情。

9

您可以使用此代碼:

actionBar.setStackedBackgroundDrawable(new ColorDrawable(yourColor)); // for example new ColorDrawable(Color.BLUE) 
+0

謝謝...現在,我可以在運行時更改它。謝謝 –

+0

這不會改變每個標籤的顏色。 – Si8

-1

更改動作條標籤的顏色,請使用此代碼:

//例如,如果你想白的顏色作爲標籤的背景,然後

getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF"))); 
+0

爲什麼你需要重新發布答案? – Dinistro