Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: styling overflow menu in action bar

I am using v7 support library in my project. My manifest settings are:

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

I used Android Action Bar Style Generator to generate styles for my Action Bar. The problem is that while everything works for the newest apis, my overflow menu does not change in low apis (tested on emulator 2.2 and real device 2.3.3 htc desire).

1
(this should have red background)

Is menu overflow loading items in some other component like spinner dialog or something (sry if that sounds dumb) ? Why styles for one api(ex 15) doesn't apply for other(ex 8), and is there anything i can do to have same overflow menu for all api versions.

This is my original generated style from Action Bar Style Generator which i tweaked a lot but with no success.

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

like image 949
BlastFire Avatar asked Aug 06 '13 17:08

BlastFire


People also ask

Where is the overflow menu button?

The Android overflow menu is accessed from the far right of the actions toolbar at the top of the display of the running app. This menu provides a location for applications to provide additional options to the user.

How to change overflow menu background color in android?

The overflow background can be changed by defining a popupMenuStyle attribute in the theme. You should extend from Widget. Sherlock. PopupMenu in your own style where you can change the android:background attribute.

What is Android overflow menu?

The overflow menu (also referred to as the options menu) is a menu that is accessible to the user from the device display and allows the developer to include other application options beyond those included in the user interface of the application.


2 Answers

I did it this way:

<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>
like image 51
Daniel López Lacalle Avatar answered Oct 24 '22 16:10

Daniel López Lacalle


For simplicity, the android: namespace pertains to anything built into the OS while anything without android: as the namespace would pertain to your application (and the libraries you are using). Most, if not all, support libraries for the ActionBar will try to use the native ActionBar implementation and therefor use the android: namespace attributes in your styles. When the native ActionBar is not available it would use the libraries implementation and the non-android: namespaced attributes. This is why you must specify every attribute with and without the android: namespace.

like image 45
JRomero Avatar answered Oct 24 '22 16:10

JRomero