Current Android Release version:
Version Code: Pie
Version: 9
API level: 28

Android: Create Menu options in Fragments

To display menu options in fragment, we have to add 'setHasOptionsMenu' method in fragment onCreate().with out this method,menu options will not be visible in fragments.
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setHasOptionsMenu(true);
}

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

No comments:

Post a Comment