自定义主题不起作用

时间:2013-11-12 06:04:57

标签: android android-theme

我必须自定义我的整个应用程序主题,我正在尝试实现我的自定义主题。

我能够实现自定义主题,但是当我在清单文件中应用它时显示错误。

这是我的客户主题代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_background</item>
    </style>
</resources>

3 个答案:

答案 0 :(得分:0)

更改为

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.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">@drawable/actionbar_background</item>
    </style>
</resources>

在清单应用主题中

 android:theme="@style/CustomActionBarTheme" >

你在清单中的min sdk应为14.如果你想支持api level 11以下的actionbar,请使用支持库中的appcompact。

同时检查此

http://developer.android.com/guide/topics/ui/actionbar.html

https://developer.android.com/training/basics/actionbar/styling.html

答案 1 :(得分:0)

您应该提供有关您获得的错误的更多详细信息。乍一看,我可以看到你正在使用Theme.Holo.Light.DarkActionBar,我认为它只适用于Android 4.x,所以如果你的目标是以前的Android版本,你可能会收到错误。

尝试将style.xml文件添加到以下每个文件夹中:

res/values
res/values-v11
res/values-v14

使用第一个文件夹的style.xml文件中的Theme.Light替换引用的主题。使用Theme.Holo.Light for v11并将Theme.Holo.Light.DarkActionBar保留在v14下的style.xml文件中。

另请注意,您无法在Honeycomb(v11)之前的版本下设置操作栏的样式。检查documentation for the ActionBar以获取更多详细信息,特别是与AppCompat库相关的信息。

我希望有所帮助。否则,请提供有关您遇到的错误的更多信息。

答案 2 :(得分:0)

<style name="CustomTheme" parent="android:Theme">
    <item name="android:windowTitleSize">35dip</item>
    <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowBackground">@color/transparent</item>
</style>

<style name="CustomWindowTitleBackground">
    <item name="android:background">@drawable/button_black</item>
</style>

将此代码放在style.xml中,只需在AndroidManifest.xml中更改应用程序标记的主题属性,如

<application android:icon="@drawable/ic_launcher"
     android:theme="@style/CustomTheme">

多数民众赞成。

相关问题