Note that there are some explanatory texts on larger screens.

plurals
  1. POOpening submenu in action bar on Hardware menu button click
    text
    copied!<p>Title explains everything. I want to open a submenu in actionbar when clicking Hardware menu button</p> <p>This is the code and it works fine first time i click menu. Every other time it just flashes(opens and the instantly closes it)</p> <pre><code>private Menu mainMenu; public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.options, menu); mainMenu = menu; return true; } public boolean onKeyDown(int keyCode, KeyEvent event) { if(event.getAction() == KeyEvent.ACTION_DOWN){ switch(keyCode) { case KeyEvent.KEYCODE_MENU: mainMenu.performIdentifierAction(R.id.more, 0); return true; } } return super.onKeyDown(keyCode, event); } </code></pre> <p>and here is options.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:id="@+id/settings" android:icon="@drawable/ic_menu_preferences" android:showAsAction="ifRoom|withText" android:title="Settings"/&gt; &lt;item android:id="@+id/about" android:icon="@drawable/ic_menu_info_details" android:showAsAction="ifRoom|withText" android:title="About"/&gt; &lt;item android:id="@+id/more" android:icon="@drawable/ic_menu_moreoverflow_normal_holo_dark" android:showAsAction="always|withText" android:title="More"&gt; &lt;menu&gt; &lt;item android:id="@+id/changelog" android:icon="@drawable/ic_menu_recent_history" android:showAsAction="ifRoom|withText" android:title="Changelog"/&gt; &lt;item android:id="@+id/update" android:icon="@drawable/ic_menu_refresh" android:showAsAction="ifRoom|withText" android:title="Update Check"/&gt; &lt;item android:id="@+id/check" android:icon="@drawable/ic_menu_help" android:showAsAction="ifRoom|withText" android:title="Compatibility Check"/&gt; &lt;/menu&gt; &lt;/item&gt; &lt;/menu&gt; </code></pre> <p><strong>UPDATE:(Solution)</strong> Just changed onKeyDown() method to onKeyUp() and now it sticks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload