How does MenuInflater work?

If I guessed that MenuInflater is an object type that can inflate (inflate, expand?) An object of type menu. But when is the method called and which Menu object is automatically passed? What does getMenuInflater () do (or is it just another way ... = new MenuInflater ())? And once an inflatable object object is created, what exactly does .inflate do? What does a submenu object do with my main.xml menu?

(I apologize if I ask too many questions at once.)

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(Menu);
}
+4
source share
2 answers

A MenuInflater - , Menu xml (, ), : Menu .

onCreateOptionMenu(Menu) Activity.openOptionsMenu().

. , , Activity , , .
Android , , , , , onCreateOptionsMenu.


ActionBar, onCreateOptionsMenu ActionBar, ActionBar. Activity. , Activity.onPrepareOptionsMenu

+6

"" - "" (XML , GUI) "" ; Android. MenuInflater class Android, .

: Android Java XML:

:

(my_menu.xml) , , MenuInflater onCreateOptionsMenu. , Androids MenuInflater XML-

+2

All Articles