0

I am trying to create a custom menu button as an Action item, here is the xml resource I used

<menu 
    xmlns:spyder="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@+id/menu_search_customers"
      android:title="@string/hello_world"
      android:icon="@android:drawable/ic_menu_search"
      spyder:showAsAction="ifRoom|collapseActionView"
      spyder:actionViewClass="android.support.v7.widget.SearchView" />

    <item
        android:id="@+id/menu_overflow"
        android:icon="@drawable/abc_ic_menu_moreoverflow_normal_holo_light"
        android:orderInCategory="11111"
        spyder:showAsAction="always">
        <menu>
            <item
                android:id="@+id/menu_overflow_item1"
                spyder:showAsAction="never"
                android:title="Item1"/>
            <item
                android:id="@+id/menu_overflow_item2"
               spyder:showAsAction="never"
                android:title="Item2"/>
        </menu>
</item>
</menu>

And here is the output

enter image description here

Menu popups when i click on action item as expected, I want to popup it on Hardware Menu button click also. is that possible?

Favas Kv
  • 2,961
  • 2
  • 28
  • 38
  • 1
    I think a quick read through: http://developer.android.com/guide/topics/ui/menus.html should be helpful – Noah Dec 11 '13 at 14:14

1 Answers1

2

You can capture the hardware menu click using the following function.

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        openOptionsMenu()
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
yajnesh
  • 2,089
  • 1
  • 23
  • 36
  • This code is for opening default android option menu but i am using ActionBar Action Item as Menu button and i want to behave it like default option menu. – Favas Kv Dec 12 '13 at 03:54