Home > Enterprise >  How can I hide a centreButton in spaceNavigationView and keep its space?
How can I hide a centreButton in spaceNavigationView and keep its space?

Time:12-21

I'm new to android programming, and there isn't so much documentation about SpaceNavigationView. I want to hide the centerButton and to keep the space given to it.

Here is the menu : menu before hiding the centre button

I want to hide the button "sos"

Here is my code :

if (settingsProfils.sos == 1) {
    space.setSpaceBackgroundColor(ContextCompat.getColor(getActivity().getApplicationContext(), R.color.gris));
    space.setCentreButtonIcon(R.drawable.sos);
    space.setActiveCentreButtonIconColor(getResources().getColor(R.color.white));
    space.setInActiveCentreButtonIconColor(getResources().getColor(R.color.white));
    space.setCentreButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), R.color.coral_pink));
    space.setFont(type);
    space.hideCenterButton(1);

} else {
    space.setSpaceBackgroundColor(ContextCompat.getColor(getActivity().getApplicationContext(), R.color.gris));
    space.setCentreButtonIcon(R.drawable.sos);
    space.setActiveCentreButtonIconColor(getResources().getColor(R.color.white));
    space.setInActiveCentreButtonIconColor(getResources().getColor(R.color.white));
    space.setCentreButtonColor(ContextCompat.getColor(getActivity().getApplicationContext(), R.color.gris));
    space.hideCenterButton(0);

}

and this is the result : after hiding the centre button

The problem is that I want to keep the space given to the button so that the other items in the menu stay in their positions (I mean they can't move).

CodePudding user response:

please show more your code project and xmls

CodePudding user response:

I solved this by adding :

CentreButton centreButton = space.getCentreButton();
centreButton.setVisibility(INVISIBLE);

And modify the last line in else block by :

space.hideCenterButton(1);
  • Related