Jaison Joseph
Jaison Joseph

Reputation: 11

How to Trigger onCreateOptionsMenu automatically

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();
    }

Upvotes: 1

Views: 568

Answers (2)

VishnuSP
VishnuSP

Reputation: 599

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.

Upvotes: 0

Sanny Nagveker
Sanny Nagveker

Reputation: 418

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

Upvotes: 1

Related Questions