简体   繁体   English

如何使用自定义操作栏背景设置android应用程序自定义主题?

[英]How to set android application custom theme with custom action bar background?

I want to set a custom theme to my android application, but unable to do so. 我想为我的android应用程序设置自定义主题,但无法这样做。 Following is my xml snippet : 以下是我的xml片段:

res/values/themes.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>

In manifest I've changed the android:theme property to : 在清单中,我将android:theme属性更改为:
android:theme="@style/CustomActionBarTheme" android:theme =“ @ style / CustomActionBarTheme”

But still, its not working for me. 但是,它对我不起作用。 The theme am getting is Theme.AppCompat.Light.DarkActionBar. 主题是Theme.AppCompat.Light.DarkActionBar。

I found the solution by modifying style.xml : 我通过修改style.xml找到了解决方案:

<!-- Base application theme. -->
<style name="CustomAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">#FF0000</item>
</style>

You need to create res/values/style.xml or make these changes in res/values/style.xml 您需要创建res / values / style.xml或在res / values / style.xml中进行这些更改

themes.xml not work in android project. themes.xml在android项目中不起作用。

And set your custom theme in your manifest in 并在清单中设置自定义主题

<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