Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android bottom navigation hiding views

private fun setupNav() {
    val navController = findNavController(R.id.nav_host_fragment)
    findViewById<BottomNavigationView>(R.id.bottomNav)
        .setupWithNavController(navController)

    navController.addOnDestinationChangedListener { _, destination, _ ->
        when (destination.id) {
            R.id.mainFragment -> showBottomNav()
            R.id.mineFragment -> showBottomNav()
            else -> hideBottomNav()
        }
    }
}

private fun showBottomNav() {
    bottomNav.visibility = View.VISIBLE

}

private fun hideBottomNav() {
    bottomNav.visibility = View.GONE

}
Comment

android hide and show bottom navigation

public class BottomNavigationViewBehavior extends CoordinatorLayout.Behavior<BottomNavigationView> {

private int height;

@Override
public boolean onLayoutChild(CoordinatorLayout parent, BottomNavigationView child, int layoutDirection) {
    height = child.getHeight();
    return super.onLayoutChild(parent, child, layoutDirection);
}

@Override
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout,
                               BottomNavigationView child, @NonNull 
                               View directTargetChild, @NonNull View target,
                               int axes, int type)
{
    return axes == ViewCompat.SCROLL_AXIS_VERTICAL;
}

@Override
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull BottomNavigationView child,
           @NonNull View target, int dxConsumed, int dyConsumed,
           int dxUnconsumed, int dyUnconsumed, 
            @ViewCompat.NestedScrollType int type)
{
   if (dyConsumed > 0) {
       slideDown(child);
   } else if (dyConsumed < 0) {
       slideUp(child);
   }
}

private void slideUp(BottomNavigationView child) {
    child.clearAnimation();
    child.animate().translationY(0).setDuration(200);
}

private void slideDown(BottomNavigationView child) {
    child.clearAnimation();
    child.animate().translationY(height).setDuration(200);
}
Comment

PREVIOUS NEXT
Code Example
Java :: Java Create a BufferedWriter 
Java :: online java code fixer 
Java :: what are abstract methods in java 
Java :: java stringbuilder set value 
Java :: Java Type conversion from String to int 
Java :: boolean in java 
Java :: prime numbers program in java 
Java :: scala vs java 
Java :: java character for end of file 
Java :: sorting collections with comparator java 
Java :: Java Converting double into an int 
Java :: java remove item from list 
Java :: iterate over multi array java 
Java :: java how to change the length of an array 
Java :: Number to decimal places in java 
Java :: java try-with-resources 
Java :: java fields 
Java :: frame background changing in java 
Java :: java spring set private field in test 
Java :: neither bindingresult nor plain target object for bean name spring mvc 
Java :: exceptions in java 
Java :: string to char 
Java :: interface in solidity 
Java :: date and time java 
Java :: treeset java descending order using comparator 
Java :: java session timeout 
Java :: array de meses java 
Java :: Error inflating class android.support.design.widget.CoordinatorLayout 
Java :: java clear scanner2 
Java :: java linkedlist poll 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =