2018-04-19 Fragment Toolbar menu

   ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
       setHasOptionsMenu(true);
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_menu, menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case R.id.action_1:
            // do stuff
            return true;

        case R.id.action_2:
            // do more stuff
            return true;
    }

    return false;
}

你可能感兴趣的:(2018-04-19 Fragment Toolbar menu)