ActionBar Overlay menu styling information for manual implementation

I am trying to duplicate overflow dropdown menu functionality for other ActionBar elements. I am working on a manual implementation of this functionality, as I think it was left out of the environment (perhaps to standardize user interfaces). Does anyone know what style / style elements are used for the dropdown when clicking on the overflow menu?

EDIT

The overflow button is actually a modified counter. Here is the style information for him.

<style name="Widget.Holo.Spinner" parent="Widget.Spinner.DropDown"> <item name="android:background">@android:drawable/spinner_background_holo_dark</item> <item name="android:dropDownSelector">@android:drawable/list_selector_holo_dark</item> <item name="android:popupBackground">@android:drawable/menu_dropdown_panel_holo_dark</item> <item name="android:dropDownVerticalOffset">0dip</item> <item name="android:dropDownHorizontalOffset">0dip</item> <item name="android:dropDownWidth">wrap_content</item> <item name="android:popupPromptView">@android:layout/simple_dropdown_hint</item> <item name="android:gravity">left|center_vertical</item> </style> 
+4
source share
2 answers

Here is a brief overview of what I put together:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dropdownContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <LinearLayout android:id="@+id/leftBuffer" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /> <LinearLayout android:layout_width="150dp" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/actionbarDropdown" style="@style/Widget.ActionBarDropDown" android:layout_width="match_parent" android:layout_height="wrap_content" android:cacheColorHint="@android:color/transparent" android:entries="@array/sortOptions" /> <LinearLayout android:id="@+id/bottomBuffer" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> <LinearLayout android:id="@+id/rightBuffer" android:layout_width="118px" android:layout_height="match_parent" /> </LinearLayout> 

Adding an onClick element to an ActionBar, which: Adds the above layout as a child to your actions. The root group of the ViewGroup gives you the illusion of a fall.

Adding onClick to each of the buffers, which removes the view from the root ViewGroup, allows the drop-down menu to β€œexit” when trying to move focus.

Style Information for Dropdown:

 <item name="android:background">@drawable/menu_dropdown_panel_holo_light</item> <item name="android:dropDownSelector">@drawable/list_selector_background</item> 

Layout for each list item:

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="48dp" android:textSize="17sp" android:gravity="right|center_vertical" style="?android:attr/dropDownItemStyle" android:ellipsize="marquee" android:id="@android:id/text1"> </TextView> 

This does not give a perfect copy of the overflow functions, but it is pretty close. I am very interested if someone else knows a way to reproduce this functionality in a more integrated way!

+2
source

I achieve this by having a simple user view that I introduced in the ActionBar:

 <?xml version="1.0" encoding="utf-8"?> <ImageButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/action_starred" android:layout_width="wrap_content" android:layout_height="match_parent" style="?android:attr/actionButtonStyle" android:src="@drawable/ic_action_star" /> 

Then I attach an OnClickListener to it in onCreateOptionsMenu() , which simply adds a fragment that takes care of creating the ListPopupWindow and sets the anchor as the kind of action. It finds the kind of action through getActivity().findViewById(R.id.action_starred) .

It's simple, you can configure the popup to be modal so that it looks more like a menu. You can use something like android.R.layout.simple_dropdown_item_1line as list items.

This method should work equally well, even if you don't put the view in an ActionBar like me.

0
source

All Articles