0

I want to replicate the menu that Google has in its applications, but I don't know if there is a component like NavigationView and DrawerLayout that allows this menu to be made but that is not fixed to the left but can be displayed centered on the screen.Screenshot of the menu I want to make

I've tried making a NavigationView inside a RelativeLayout (without DrawerLayout ) and centering it manually, but I'm not sure if this is the right thing to do.

1
  • Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented Jul 9 at 19:36

1 Answer 1

0

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"));

Not the answer you're looking for? Browse other questions tagged or ask your own question.