簡體   English   中英

Android操作欄主題不適用

[英]Android action bar theme not applying

我最近開始進行android開發,並且一般都沒有問題。 但是,盡管遵循了這封信的指南/說明(或可以告訴我),但我似乎無法將主題應用於操作欄。

我使用Android操作欄樣式生成器生成了主題,將res文件夾添加到了項目中,並編輯了清單文件以使用新主題。 我在values和values-v14中都有一個樣式,后者使用“ android:”。

所需結果當前結果

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

在正確方向上的任何幫助將不勝感激。

如果您使用的Android支持庫..適用於Android <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>

對於最后一張圖片,您需要使用父樣式的itemBackground屬性,如下所示:

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

讓我知道這是否可以解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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