1

I want to show onCreateOptionsMenu which is on the right top side of the application. without touching on the three dots. what i am actually planing to do is, when the app runs for the first time i want show the menu items to user automatically, how can i do that see the screenshot to get more details

    SharedPreferences preferences=  PreferenceManager.getDefaultSharedPreferences(this);
    if (!preferences.getBoolean("Time",false))
    {

     // code to trigger onCreateOptionsMenu

        Toast.makeText(getApplicationContext(), "Showing menu items ", Toast.LENGTH_LONG).show();
        SharedPreferences.Editor editor=preferences.edit();
        editor.putBoolean("Time",true);
        editor.commit();
    }
  • 1
    If you are searching for something that you'd like todo in code, it's good to search for _How to ... programmatically_ which yields - beside many stack overflow answers - this answer with many cases f.e. for AppCompat/Toolbar and the troubles of `onCreate`: http://stackoverflow.com/questions/3133318/how-to-open-the-options-menu-programmatically and another thing, if you want to call an action for the UI (on UI Thread) Programmatically it may be good to checkout http://stackoverflow.com/questions/12850143/android-basics-running-code-in-the-ui-thread – makadev May 05 '17 at 08:47

2 Answers2

1

You can do it in one single method openOptionsMenu(); call it in onCreate if you want it initially opened.

Sanny Nagveker
  • 418
  • 3
  • 7
0

If your MainActivity inherits from Activity, you can use openOptionsMenu();. If you use Toolbar, then go for toolbar.showOverflowMenu()

From your question, As most of the Android mobile users are aware of the overflow/three-dot option, a demo may not be required. If you really feel that user should know about the overflow items, you can show user hints/direction for which many libraries are available.

Community
  • 1
  • 1
VishnuSP
  • 599
  • 5
  • 16