ActionBar设置区域的自定义背景颜色

时间:2014-11-17 20:43:45

标签: java android android-actionbar settings

我想更改位于ActionBar上的设置选项卡的颜色,我在这里和其他来源做了非常广泛的研究。

我的Android版本为4.4.2.

我的清单以这种方式宣布:

    <uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="19" />

基本上我正在做其他消息来源给我的建议:

<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:panelFullBackground">@drawable/menu_background</item>
</style>

我还将android:panelFullBackgroundandroid:panelBackgroundandroid:panelColorBackground的{​​{1}}属性替换为可绘制资源切换为每个没有结果的颜色值。

最后我还尝试使用ListPopupWindow父变体:

android:panelColorForeground

此处我还更改了<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light"> </style> <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <item name="android:popupMenuStyle">@style/PopupMenu</item> </style> <style name="PopupMenu" parent="@android:style/Widget.Holo.ListPopupWindow"> <item name="android:panelFullBackground">@drawable/menu_background</item> </style> android:panelFullBackground属性的android:panelColorBackground属性,将它们与android:popupBackground@android:color资源混合在一起,但也无法正常工作

您能告诉我一个通过styles.xml文件配置的有效方法吗?

非常感谢

2 个答案:

答案 0 :(得分:2)

也许你需要使用Android Asset studio's ActionBarStyleGenerator来轻松处理颜色,而不是通过所有的东西。如果您需要在每个Tab上进行更多自定义,那么您需要使用getActionBar()(或者在支持操作栏的情况下使用getSupportActionBar())获取对操作栏的引用,并以编程方式创建自定义视图并使用addTab(...)将它们添加到操作栏

答案 1 :(得分:0)

我设法为我的样式找到了正确的设置来完成操作栏设置自定义颜色。这篇文章也有帮助:How to change the background color of Action Bar's Option Menu in Android 4.2?

样式就是这样:

文件 styles.xml

<resources>

<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>

<style name="AppTheme" parent="android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBarTheme</item>        
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
    <item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>

<style name="MyActionBarTheme" parent="@android:Widget.Holo.Light.ActionBar">
    <item name="android:background">#3892D3</item> 
    <item name="android:titleTextStyle">@style/MyActionBarTheme.Text</item>        
</style>    

<!-- 
This style reference did it, you can put a drawable resource or color resource reference there as well. For example: @drawable/menu_dropdown_image or @android:color/white 
-->  
<style name="PopupMenu" parent="@android:Widget.Holo.Light.ListPopupWindow">
    <item name="android:popupBackground">#3892D3</item>        
</style>
<!---->

<style name="MyActionBarTheme.Text" parent="@android:TextAppearance">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textSize">20sp</item>
</style>    

<style name="TextAppearance">
    <item name="android:textColor">@android:color/white</item>
</style>

</resources>

谢谢!