I am using a bottom app bar with a Navigation Drawer. When I click on one item of the drawer, a new fragment is added on top of my Main activity. Inside this fragment I want to have a RecyclerView. When the fragment is attached, I want to see the normal menu that I am inflating on the MainActivity, but when an item is clicked on the recycler view I want to replace the menu with a custom one. Right now It´s just adding more items to be existing menu. How I can replace with a new menu, and make the Fab Button disappear or move to the right?
The button is just to simulate the click on my future RecyclerCiew.
public class CourseFragment extends Fragment {
private Menu mMenu;
private MenuInflater mInflater;
public CourseFragment() {
// Required empty public constructor
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.fragment_course, container, false);
Button btn=view.findViewById(R.id.button);
btn.setOnClickListener(v->{
mInflater.inflate(R.menu.bottomappbar_edit_remove_menu,mMenu);mMenu.
});
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
mMenu=menu;
mInflater=inflater;
//inflater.inflate(R.menu.bottomappbar_main_menu,menu);
//super.onCreateOptionsMenu(menu,inflater);
}
}