Android操作栏主题不适用

时间:2014-04-16 19:33:50

标签: android android-layout

我最近开始进行Android开发,它一般都没有问题。但是,我似乎无法在操作栏中应用主题,尽管遵循指南/指示信(或者我可以告诉)。

我使用Android操作栏样式生成器生成了我的主题,将res文件夹添加到我的项目中并编辑了清单文件以使用新主题。我有两种价值观和价值观的风格 - 后者使用" android:"。

期望的结果 vs 当前结果

RES /值/ styles_amulettheme.xml:

<?xml version="1.0" encoding="utf-8"?>
    <!-- File created by the Android Action Bar Style Generator

         Copyright (C) 2011 The Android Open Source Project
         Copyright (C) 2012 readyState Software Ltd

         Licensed under the Apache License, Version 2.0 (the "License");
         you may not use this file except in compliance with the License.
         You may obtain a copy of the License at

              http://www.apache.org/licenses/LICENSE-2.0

         Unless required by applicable law or agreed to in writing, software
         distributed under the License is distributed on an "AS IS" BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         See the License for the specific language governing permissions and
         limitations under the License.
    -->

    <resources>

        <style name="Theme.Amulettheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
            <item name="actionBarItemBackground">@drawable/selectable_background_amulettheme</item>
            <item name="popupMenuStyle">@style/PopupMenu.Amulettheme</item>
            <item name="dropDownListViewStyle">@style/DropDownListView.Amulettheme</item>
            <item name="actionBarTabStyle">@style/ActionBarTabStyle.Amulettheme</item>
            <item name="actionDropDownStyle">@style/DropDownNav.Amulettheme</item>
            <item name="actionBarStyle">@style/ActionBar.Solid.Amulettheme</item>
            <item name="actionModeBackground">@drawable/cab_background_top_amulettheme</item>
            <item name="actionModeSplitBackground">@drawable/cab_background_bottom_amulettheme</item>
            <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Amulettheme</item>

                    <!-- Light.DarkActionBar specific -->
            <item name="actionBarWidgetTheme">@style/Theme.Amulettheme.Widget</item>

        </style>

        <style name="ActionBar.Solid.Amulettheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
            <item name="background">@drawable/ab_solid_amulettheme</item>
            <item name="backgroundStacked">@drawable/ab_stacked_solid_amulettheme</item>
            <item name="backgroundSplit">@drawable/ab_bottom_solid_amulettheme</item>
            <item name="progressBarStyle">@style/ProgressBar.Amulettheme</item>
        </style>

        <style name="ActionBar.Transparent.Amulettheme" parent="@style/Widget.AppCompat.ActionBar">
            <item name="background">@drawable/ab_transparent_amulettheme</item>
            <item name="progressBarStyle">@style/ProgressBar.Amulettheme</item>
        </style>

        <style name="PopupMenu.Amulettheme" parent="@style/Widget.AppCompat.PopupMenu"> 
            <item name="android:popupBackground">@drawable/menu_dropdown_panel_amulettheme</item>   
        </style>

        <style name="DropDownListView.Amulettheme" parent="@style/Widget.AppCompat.ListView.DropDown">
            <item name="android:listSelector">@drawable/selectable_background_amulettheme</item>
        </style>

        <style name="ActionBarTabStyle.Amulettheme" parent="@style/Widget.AppCompat.ActionBar.TabView">
            <item name="android:background">@drawable/tab_indicator_ab_amulettheme</item>
        </style>

        <style name="DropDownNav.Amulettheme" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
            <item name="android:background">@drawable/spinner_background_ab_amulettheme</item>
            <item name="android:popupBackground">@drawable/menu_dropdown_panel_amulettheme</item>
            <item name="android:dropDownSelector">@drawable/selectable_background_amulettheme</item>
        </style>

        <style name="ProgressBar.Amulettheme" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
            <item name="android:progressDrawable">@drawable/progress_horizontal_amulettheme</item>
        </style>

        <style name="ActionButton.CloseMode.Amulettheme" parent="@style/Widget.AppCompat.ActionButton.CloseMode">
            <item name="android:background">@drawable/btn_cab_done_amulettheme</item>
        </style>

        <!-- this style is only referenced in a Light.DarkActionBar based theme -->
        <style name="Theme.Amulettheme.Widget" parent="@style/Theme.AppCompat">
            <item name="popupMenuStyle">@style/PopupMenu.Amulettheme</item>
            <item name="dropDownListViewStyle">@style/DropDownListView.Amulettheme</item>
        </style>

    </resources>

AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="quinn.anth.amulet"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Amulettheme" >
        <activity
            android:name="quinn.anth.amulet.MenuActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

非常感谢任何正确方向的帮助。

2 个答案:

答案 0 :(得分:0)

如果您使用Android支持库..适用于Android&lt;的设备3.0版本。 您应将操作栏背景名称用作background,将其他更高版本用作android:background

像这样更改自定义主题

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/Blue</item>
    <item name="background">@color/Blue</item>
</style>

答案 1 :(得分:0)

对于最后一张图片,您需要在父样式中使用itemBackground属性,如下所示:

<style name="Theme.Amulettheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:itemBackground">@drawable/item_background</item>
</style>  

请告诉我这是否可以解决您的问题。