If you want to make a menu like google, its actually much less complicated then we think. We can do this without using NavigationView. Just create a simple layout file and make the design of your menu in it. After that we will use a DialogFragment to show the menu. The DialogFragment should look like this:
public class MenuDF extends DialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.menu_layout, container, false);
}
@Override
public void onStart() {
super.onStart();
if (getDialog() != null && getDialog().getWindow() != null) {
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
}
}
Then we can trigger the menu in our fragment file. like this:
findViewById(R.id.menu_button).setOnClickListener(v -> new MenuDF().show(getSupportFragmentManager(), "MenuDF"));