簡體   English   中英

如何使用自定義操作欄背景設置android應用程序自定義主題?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM