What is onCreateOptionsMenu(Menu menu)

前端 未结 4 1027
太阳男子
太阳男子 2020-12-29 08:23

What are the two parameters Menu and menu in method onCreateOptionsMenu(Menu menu) and how to use this method. I have another question why this pa

4条回答
  •  萌比男神i
    2020-12-29 09:00

    When onCreateOptionsMenu is called?

    onCreateOptionsMenu() is called by the Android runtime when it need to create the option menu.

    Android Developer Guide: Menus

    If you've developed your application for Android 2.3.x and lower, the system calls onCreateOptionsMenu() to create the options menu when the user opens the menu for the first time. If you've developed for Android 3.0 and higher, the system calls onCreateOptionsMenu() when starting the activity, in order to show items to the app bar.

    How to build an option menu?

    Please refer to other anwsers.

    Why onCreateOptionsMenu return Boolean

    Activity.html#onCreateOptionsMenu

    You must return true for the menu to be displayed; if you return false it will not be shown.

    Why onOptionsItemSelected return Boolean

    When you successfully handle a menu item, return true. If you don't handle the menu item, you should call the superclass implementation of onOptionsItemSelected() (the default implementation returns false).

提交回复
热议问题