I'm using the single activity multi fragments with navigation component.how do i hide the bottom navigation bar for some of the fragments?
i tried the following:
activity_main.xml:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:visibility="@{viewModel.uiUtils.shouldShow ? View.VISIBLE:View.GONE}"/>
mainactivity.java:
private void observeShouldShow() {
mainViewModel.uiUtils.getShouldShow().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
ViewGroup.LayoutParams layoutParams = binding.bottomNavigation.getLayoutParams();
if (mainViewModel.getUiUtils().getShouldShow().getValue()) {
binding.bottomNavigation.setVisibility(View.VISIBLE);
layoutParams.height = 170;
binding.bottomNavigation.setLayoutParams(layoutParams);
} else {
layoutParams.height = 0;
binding.bottomNavigation.setLayoutParams(layoutParams);
binding.bottomNavigation.setVisibility(View.INVISIBLE);
}
}
});
the bottomnavbar blinks when switching between full screen fragments and normal fragments
i used OnDestinationChangedListener, as @Lavepe answered ... sorry didnt check here for a long time here is my code:
if (destinationLabel.equals("FragmentX")) {
showBottomNav(true);
badgeBehaviour(false, false);}
the ui function:
private void showBottomNav(boolean b) {
binding.bottomNavigation.setVisibility(b ? View.VISIBLE : View.GONE);
}
the view above it is :
<fragment
android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/viewcartbadge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
Best Regards Hope You Find it Useful