2017-05-05 75 views
1

我想说明onCreateOptionsMenu这是对应用程序的右上角侧。而不触及三个点。什么我其实刨做的是,当应用程序的第一次,我想自动显示菜单项,用户运行,我怎么能做到这一点see the screenshot to get more details如何触发onCreateOptionsMenu自动

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

如果您正在寻找的东西,你想在代码中的待办事项,这是很好的搜索_How到... programmatically_这将产生 - 旁多堆栈溢出的答案 - 这答案有很多情况下F.E.对于程序兼容性/工具栏和onCreate'的'烦恼:http://stackoverflow.com/questions/3133318/how-to-open-the-options-menu-programmatically和另一件事,如果你想呼吁的行动UI(用户界面上的螺纹)编程它可能是好签http://stackoverflow.com/questions/12850143/android-basics-running-code-in-the-ui-thread – makadev

回答

1

您可以在一个单一的方法去做openOptionsMenu(); 如果您希望最初打开它,请在onCreate中调用它。

+0

我可以简单地调用openOptionsMenu();打开菜单? –

+1

它没有打开任何东西 –

0

如果您的MainActivity从Activity继承,你可以使用openOptionsMenu();。 如果使用Toolbar,然后去toolbar.showOverflowMenu()

从你的问题,由于大部分Android手机的用户都知道的溢/三个点的选项,可能不需要演示。如果你真的觉得用户应该知道溢出项目,你可以显示许多libraries可用的用户提示/方向。