0
<item
        android:id="@+id/members"
        android:orderInCategory="100"
        android:title="@string/members"
        app:showAsAction="never" />


 @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.menu_chat_activity, menu);
            return super.onCreateOptionsMenu(menu);
        }





 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // Respond to the action bar's Up/Home button

            case R.id.members:
                Intent intent = new Intent(this, GroupDetailActivity.class);
                intent.putExtra("name", toolbarText);
                intent.putExtra("groupId", currentGroupId);
                startActivity(intent);
                break;

            case android.R.id.home:
                finish();

                }
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

i have an activity with toolbar containing a home and an item members the code works fine but if i tap hardware menu button on the device the menu item members is showing on the bottom of the device rather than anchor for the toolbar

Vaisakh N
  • 780
  • 1
  • 11
  • 27
  • Read this http://stackoverflow.com/questions/9286822/how-to-force-use-of-overflow-menu-on-devices-with-menu-button and this http://developer.android.com/design/patterns/compatibility.html – Emil Oct 01 '15 at 05:51
  • @vaisakh is my answer below working? – Vinay Jayaram Oct 01 '15 at 08:14

1 Answers1

1

Add this code snippet in your onCreate method,

ActionBar actionBar = getActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
         try {
                ViewConfiguration config = ViewConfiguration.get(this);
                Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
                if(menuKeyField != null) {
                    menuKeyField.setAccessible(true);
                    menuKeyField.setBoolean(config, false);
                }
            } catch (Exception ex) {
                // Ignore
            }
Vinay Jayaram
  • 1,030
  • 9
  • 29