Android:如何在操作栏中为溢出菜单添加样式

6

我在项目中使用v7支持库。我的清单设置如下:

    android:minSdkVersion="7"
    android:targetSdkVersion="15"

我使用了Android Action Bar Style Generator来为我的Action Bar生成样式。问题在于,尽管最新的API一切正常,但我的溢出菜单在低版本的API(在模拟器2.2和真实设备2.3.3 htc desire上测试)中没有改变。 1
(这应该有红色背景)
菜单溢出是否在加载其他组件(如Spinner对话框)中的项目(如果听起来很蠢,请原谅)?为什么一个API(例如15)的样式不适用于另一个API(例如8),我能做些什么来使所有API版本都有相同的溢出菜单?
这是我从Action Bar Style Generator中生成的原始样式,我进行了很多调整,但没有成功。
<resources>

<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>

2个回答

3
我是这样做的:
<style name="Theme.yourapp" parent="@style/Theme.AppCompat.Light.DarkActionBar">
  <item name="android:actionBarWidgetTheme">@style/Theme.yourapp.Widget</item>
</style>

<style name="Theme.yourapp.Widget" parent="@style/Theme.AppCompat">
  <item name="android:textColor">@android:color/black</item>
</style>

2
为简化起见,android: 命名空间涉及操作系统内置内容,而没有 android: 命名空间的内容则涉及您的应用程序(以及您正在使用的库)。大多数支持 ActionBar 的库将尝试使用本机 ActionBar 实现,因此在样式中使用 android: 命名空间属性。当本机 ActionBar 不可用时,它将使用库的实现和非 android: 命名空间的属性。这就是为什么您必须同时指定带有和不带有 android: 命名空间的每个属性的原因。

实际上我已经尝试过了,但是没有效果。我花了几个小时去寻找解决方法,最后发现清除 Lint 标记可以消除 Eclipse 给我的警告。你能否指定需要使用 android: 命名空间重新编写的属性?也许我做错了什么。 - BlastFire
你是否使用了正确的目录?你应该至少拥有valuesvalues-v11和带有Android命名空间属性的values-11 - JRomero
好的,我有两个由AB样式生成器生成的值目录。values和values-v14。在values中,属性是不带android:命名空间的,在values-v14中则是WITH android:。 - BlastFire

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接