2013-06-21 150 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