【问题标题】:Android: styling overflow menu in action barAndroid:操作栏中的样式溢出菜单
【发布时间】:2013-08-06 17:40:00
【问题描述】:

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

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

我使用 Android 操作栏样式生成器为我的操作栏生成样式。问题是,虽然一切都适用于最新的 api,但我的 溢出菜单 在低 api 中没有改变(在模拟器 2.2 和真实设备 2.3.3 htc 需求上测试)。


(这应该有红色背景)

菜单是否在其他组件(如微调框对话框或其他组件)中溢出加载项目(如果这听起来很愚蠢,请抱歉)?为什么一个 api(ex 15)的样式不适用于其他(ex 8),我可以做些什么来为所有 api 版本设置相同的溢出菜单。

这是我从操作栏样式生成器生成的原始样式,我对其进行了很多调整,但没有成功。

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

【问题讨论】:

    标签: android menu styles overflow


    【解决方案1】:

    我是这样做的:

    <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: 命名空间的每个属性。

      【讨论】:

      • 其实我做到了。但没有任何效果..我花了几个小时才发现清除棉绒标记消除了日食给我的警告。你能指定需要用 android: 命名空间再次写入的属性吗?也许我做错了什么。
      • 您是否使用了正确的目录?你应该至少有valuesvalues-v11values-11 中的android 命名空间属性。
      • 好吧,我有两个由 AB 样式生成器生成的值目录。价值观和价值观-v14。在 values 属性中使用没有 android: 命名空间和在 values-v14 WITH android: