Monday, 15 April 2013

android - How do I open a drop menu from a button in action bar -



android - How do I open a drop menu from a button in action bar -

i'm developing app android needs have button in action bar(near overflow) opens drop menu menu comes out clicking on overflow button. ideas? give thanks you

what can adding item action bar filling associated inflated xml file. on res/menu/action_bar.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <item android:id="@+id/new_popup" android:title="a popup example" app:showasaction="always" // not forget set showasaction item not grouped overflow android:visible="true"> <menu> // popup items inserted programmatically here adding item.getsubmenu().add(...) (see code below) </menu> </item> <item> // overflow items. hidden here (you set showasaction never) ... </item> </menu>

on activity can inflate menu :

@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.action_bar, menu); homecoming true; }

then, populate items on menu , handle click event on items:

@override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if (id == r.id.new_popup) { item.getsubmenu().add(0, itemid, order, "your text").seticon(your icon).setonmenuitemclicklistener(new onmenuitemclicklistener() { // handle item click event } // add together more items! }

android button drop-down-menu overflow

No comments:

Post a Comment