Question

I develop an app, it works fine on 4.2.2 on my LG g2, but I upgrade my android to 4.4.2 and then in my app the menu is not working. (I use pageviewer and fragment) Here is my code:

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.layout.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{

    switch (item.getItemId())
    {
    case R.id.menu_bookmark:
        //do something
      return true;
      default:
        return super.onOptionsItemSelected(item);
    }
} 

here is my log when I press menu :

03-15 02:04:31.943: I/ViewRootImpl(9878): ViewRoot's KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_MENU, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=1456794, downTime=1456794, deviceId=-1, source=0x101 } to com.android.internal.policy.impl.PhoneWindow$DecorView{42808620 V.E..... R....... 0,0-1080,1776}
03-15 02:04:32.013: I/ViewRootImpl(9878): ViewRoot's KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MENU, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=1456859, downTime=1456794, deviceId=-1, source=0x101 } to com.android.internal.policy.impl.PhoneWindow$DecorView{42808620 V.E..... R....... 0,0-1080,1776}

my menu layout file:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/menu_bookmark" 
          android:title="@string/logout_menu" />


</menu>

Is there any different on kitkat on logic?

thanks

Was it helpful?

Solution

I found a different solution; I use keyevent to detect menu button pressed, so I put a function which do as same as my menu,

here is code:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if (keyCode == KeyEvent.KEYCODE_MENU)
    {
       //my menu code here, 
    }

    return super.onKeyDown(keyCode, event);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top