Theme.AppCompat.Light.DarkActionBar样式不起作用/加载

时间:2014-11-13 00:19:16

标签: android load themes android-appcompat

我已经在这里尝试了答案,然后再回答这个问题:Theme.AppCompat.Light.DarkActionBar - No resource found。{/ p>

所以...我没有编译错误,app运行,但没有加载我的样式主题,它基于Appcompat.Light.DarkActionBar,而不是它似乎加载设备默认主题。

仔细看看,我注意到以下几点:

enter image description here

所以,我猜Eclipse没有找到Theme.Appcompat.Light.DarkActionBar并且加载了设备默认值。它似乎也不是它找不到的唯一主题。我没有错误地抱怨未找到资源。

问题:如何恢复主题?

编辑:我使用AppCompat-v7作为项目库并注意正确加载,按照此问题第一行中提到的步骤进行操作并尝试更改所有内容。 下面是样式代码,我知道它有效,因为在我重新安装Eclipse之前它确实有效,并且是由主题样式生成器生成的:http://jgilfelt.github.io/android-actionbarstylegenerator/

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

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

<style name="ActionBar.Solid.Example" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="background">@drawable/ab_solid_example</item>
    <item name="backgroundStacked">@drawable/ab_stacked_solid_example</item>
    <item name="backgroundSplit">@drawable/ab_bottom_solid_example</item>
    <item name="progressBarStyle">@style/ProgressBar.Example</item>
</style>

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

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

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

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

<style name="DropDownNav.Example" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
    <item name="android:background">@drawable/spinner_background_ab_example</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_example</item>
</style>

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

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

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

<style name="btnStyleGenoa" parent="@android:style/Widget.Button">
    <item name="android:textSize">15sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:gravity">center</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">0.6</item>
    <item name="android:background">@drawable/button_selector</item>
    <item name="android:paddingLeft">5dp</item>
</style>

<style name="CustomDialogTheme" parent="">
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:padding">0dp</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:fitsSystemWindows">true</item>
    <item name="android:listSelector">@drawable/list_selector</item>
</style>

2 个答案:

答案 0 :(得分:0)

<style name="Theme.Example" parent="Theme.AppCompat.Light.DarkActionBar">

从您的所有@style/属性中删除“parent”前缀。

答案 1 :(得分:0)

好吧,因为没有太多细节,我想你可能已经忘记了你需要在每个活动中扩展ActionBarActivity。

public class MainActivity extends ActionBarActivity

此视频解释得很好:

https://www.youtube.com/watch?v=h57QpXp2TRg