1
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ( keyCode == KeyEvent.KEYCODE_MENU ) {
        Log.d(TAG, "MENU pressed");
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

Here i want to use this functionality using image button inside my application

  if ( keyCode == KeyEvent.KEYCODE_MENU ) {
                Log.d(TAG, "MENU pressed");
                return true;
        }

is there any possibilities?

rajeshlawrance
  • 549
  • 2
  • 6
  • 25

2 Answers2

0

Assuming that you want to open the menu on the click event of your ImageButton, You have to use

openOptionsmenu(); 

inside ImageButton's onClickListener.

 imageButton.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                openOptionsMenu();
            }
        });
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • do u want to open menu during the imageButton click or need to do something else? can you tell me that please – Andro Selva Jun 21 '12 at 06:20
  • yes.i dont want to open menu but ,if i click the image button,menu button functionality will work without using openOptionsMenu... – rajeshlawrance Jun 21 '12 at 06:25
  • Oh, if that's the case, you have to call the method what you have used in ur menu. If you try to get the key Code event of Menu button, it won't work as you expected. So simple call the method inside ImageButton's onClick event to do the task. – Andro Selva Jun 21 '12 at 06:27
  • if using game application,firing while using menu button,instead of this ,i have to use image button – rajeshlawrance Jun 21 '12 at 06:29
  • can we call this method inside onclick if ( keyCode == KeyEvent.KEYCODE_MENU ) {} – rajeshlawrance Jun 21 '12 at 06:32
  • But clicking on Image Button will not trigger KeyEvent KEYCODE_MENU. How r u planning on doing that? – Andro Selva Jun 21 '12 at 06:40
0

It is handled by framework itself and never delivered to applications.

But you can achieve it using Reflection. See this post here

Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300