[英]How to set android application custom theme with custom action bar background?
我想為我的android應用程序設置自定義主題,但無法這樣做。 以下是我的xml片段:
res / values / themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
</resources>
在清單中,我將android:theme屬性更改為:
android:theme =“ @ style / CustomActionBarTheme”
但是,它對我不起作用。 主題是Theme.AppCompat.Light.DarkActionBar。
我通過修改style.xml找到了解決方案:
<!-- Base application theme. -->
<style name="CustomAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#FF0000</item>
</style>
您需要創建res / values / style.xml或在res / values / style.xml中進行這些更改
themes.xml在android項目中不起作用。
並在清單中設置自定義主題
<application ...
android:theme="@style/Your_Custom_Theme_Name"
>
...
</application>
在res/values/style.xml
添加CustomActionBarTheme
主題,它將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.