基于Appcompat的ActionBar主题不适用于较新的设备

时间:2014-12-09 16:13:07

标签: android xml android-actionbar android-appcompat android-actionbar-compat

我使用工具ActionBar样式生成器(http://jgilfelt.github.io/android-actionbarstylegenerator)创建了ActionBar样式;我在样式兼容性选择列表中选择了appcombat,因为我需要我的应用程序与Android 2.3设备兼容;但是当我下载并实现主题时,样式只显示在我的Android 2.3模拟设备上;在较新的设备中,它只显示了那些聋人。这是代码:

/values/styles.xml

    <?xml version="1.0" encoding="utf-8"?>
<resources>

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

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

    </style>

    <style name="ActionBar.Solid.Iedecap" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="background">@drawable/ab_solid_iedecap</item>
        <item name="backgroundStacked">@drawable/ab_stacked_solid_iedecap</item>
        <item name="backgroundSplit">@drawable/ab_bottom_solid_iedecap</item>
        <item name="progressBarStyle">@style/ProgressBar.Iedecap</item>
    </style>

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

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

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

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

    <style name="DropDownNav.Iedecap" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
        <item name="android:background">@drawable/spinner_background_ab_iedecap</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_iedecap</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_iedecap</item>
    </style>

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

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

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

的AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hipano.idecapmovil" >

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name" >
        </activity>

        <activity
            android:name=".Register"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".DashboardActivity"
            android:label="@string/title_activity_dashboard" >
        </activity>
    </application>

</manifest>

我认为这很奇怪,因为我的整个代码都是由自动工具生成的。 提前致谢

1 个答案:

答案 0 :(得分:3)

根据您使用的操作栏样式生成器顶部的注释,它已被弃用,不适用于AppCompat v21。

根据Using the Material Theme training,Material主题(以及AppCompat主题的backport / use Material主题)主题主要由colorPrimary和其他类似属性完成。

您可以在AppCompat v21 blog post中找到有关如何使用AppCompat / Material主题的更多详细信息。