Android - Menu

1 - About

UI - Menu (toolbar)

2 - XML Example

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="">
    <item android:id="@+id/new_game"
    <item android:id="@+id/help"
          android:title="@string/help" />


3 - Java Inflate

If both your activity and fragment(s) declare items for the options menu, they are combined in the UI. The activity's items appear first, followed by those of each fragment in the order in which each fragment is added to the activity. If necessary, you can re-order the menu items with the android:orderInCategory attribute in each <item> you need to move.

3.1 - Activity

To specify the options menu for an activity, override onCreateOptionsMenu()

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(, menu);
    return true;

3.2 - Fragment

public void onCreate(Bundle savedInstanceState) {
	setHasOptionsMenu(true); // Report that this fragment has a menu and that therefore the onCreateOptionsMenu(Menu, MenuInflater) and related methods will be called back.

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
	inflater.inflate(, menu);

public boolean onOptionsItemSelected(MenuItem item) {
	int id = item.getItemId();
	if (id == {
		// Do what you want
		return true;
	return super.onOptionsItemSelected(item);

4 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap