openOptionsMenu() across android versions

2019-05-31 16:36发布

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条回答
三岁会撩人
2楼-- · 2019-05-31 16:45

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.

查看更多
登录 后发表回答