2013-06-21 148 views
0

這個問題已經在棧溢出請求,但沒有爲我工作。更改Android中的操作欄顏色

我想只改變我的動作欄顏色,就像facebook應用程序的頂部動作是藍色的,其餘的東西有白色背景色。

我嘗試使用堆棧溢出的帖子,但它將我的完整活動顏色更改爲白色,而不僅僅是操作欄。

這是我style.xml和

<style name="CustomActivityTheme" parent="@android:style/Theme.Holo"> 
    <item name="android:actionBarTabStyle">@color/blue_base</item> 
    <!-- other activity and action bar styles here --> 
</style> 

的manifest.xml

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/CustomActivityTheme"> 

感謝。

+0

您的目標API級別是什麼? –

+0

現在是17。 android:minSdkVersion =「11」 android:targetSdkVersion =「17」 – user2510115

回答

2

不能使用顏色直接,你必須使用一個可繪製:

action_bar_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/blue_base"/> 
</shape> 

那麼這應該工作:

<item name="android:actionBarTabStyle">@drawable/action_bar_bg</item> 
+0

Thanks!是工作 – user2510115

0

現在我意識到你做錯了什麼。您無法將顏色傳遞到actionBarTabStyle,您必須傳遞樣式。相反,你可以定義你style並將它傳遞給它這個樣子,

<style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar"> 
    <item name="android:background">@drawable/ab_background</item> 
</style> 

這個例子從Android Developers頁面,如果你在那裏看一看他們很好地解釋。

還有另一篇好文章Android Developers Blog