[英]How to set background color of android app and background of action bar
我正在嘗試將我的應用修改為具有深藍色背景的深藍色操作欄。 到目前為止,我只能將整個應用程序設置為深藍色。 如何修改代碼以使操作欄保持現在的顏色,但使帶有團隊編號的背景變為淺藍色? 請注意,我的應用程序的最低API為14。
我目前在我的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>
如果選擇使用Theme.AppCompat ,則可以使用以下方式更改操作欄的背景顏色:
<item name="colorPrimary">#ffffff</item>
但是,如果您選擇“ Holo”之一,則可以使用
<item name="android:colorPrimary">#ffffff</item>
希望這可以幫助。
據我所知,您的代碼很好,而不是Widget.Holo.Light.ActionBar
因為它不是AppCompat v7的一部分。 改用這個
<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>
它應該工作正常!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.