openOptionsMenu() across android versions

2019-05-31 16:26发布

问题:

I have an app that's been designed with the titlebar hidden in all intents. I want to utilize Activity.openOptionsMenu() from a button. It works fine on 2.2 but when I run the app on honeycomb, calling openOptionsMenu() doesn't seem to work. Is there another way?

onclick code here, if it matters. This is inside my mapview activity, extending MapView:

  OnClickListener ocl =  new OnClickListener()
  {

     @Override
     public void onClick (View v)
     {
        switch (v.getId ())
        {
           case R.id.b_options:
                                  Log.d (TAG, "options clicked");
                                  mymapview.this.openOptionsMenu ();
           break;

           case R.id.b_prev:
                                  Log.d (TAG, "prev clicked");
           break;
        }

     }
  };

回答1:

Do you have an ActionBar in your application? I believe openOptionsMenu() only works with an accompanying ActionBar in Honeycomb. ICS doesn't bring back the menu button, but you no longer need an ActionBar for openOptionsMenu() to work.