简体   繁体   English

如何设置Android应用的背景色和操作栏背景

[英]How to set background color of android app and background of action bar

I am trying to modify my app to have a dark blue action bar with a light blue background. 我正在尝试将我的应用修改为具有深蓝色背景的深蓝色操作栏。 So far I have only been able to make the entire app dark blue. 到目前为止,我只能将整个应用程序设置为深蓝色。 How can I modify my code to keep the action bar the color it is now but make the background with the team numbers a light blue? 如何修改代码以使操作栏保持现在的颜色,但使带有团队编号的背景变为浅蓝色? Please note my apps minimum API is 14. 请注意,我的应用程序的最低API为14。

RR深蓝色侦察兵

I am currently using the following code in my styles.xml: 我目前在我的styles.xml中使用以下代码:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:background">@color/teamLightBlue</item>
</style>

<!-- Activity themes -->

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

<style name="Theme.Sample" parent="Theme.Base" />


<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
    parent="AppTheme">
    <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@color/teamDarkBlue</item>
</style>

If you choose to use Theme.AppCompat , you can change Action Bar's background color using: 如果选择使用Theme.AppCompat ,则可以使用以下方式更改操作栏的背景颜色:

<item name="colorPrimary">#ffffff</item>

but if you choose the Holo one, you can change that color using 但是,如果您选择“ Holo”之一,则可以使用

<item name="android:colorPrimary">#ffffff</item>

Hope this helps. 希望这可以帮助。

As far as I know your code is good instead of Widget.Holo.Light.ActionBar as its not part of AppCompat v7. 据我所知,您的代码很好,而不是Widget.Holo.Light.ActionBar因为它不是AppCompat v7的一部分。 Use this instead 改用这个

<style name="CustomActionBarTheme" parent="AppTheme">
    <item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBarTheme</item>
    <item name="actionBarStyle">@style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/teamDarkBlue</item>
    <item name="background">@color/teamDarkBlue</item>
</style>

It should work fine! 它应该工作正常!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM