0

I have the below code. How can i hide the bottom Navigation on scroll down and show when user scrolls up? What I need is the navigation to hide when user is scrolling down , once the user begins to scroll up, the navigation should reappear. XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolBar">

        <LinearLayout
           ////////
        </LinearLayout>

    </ScrollView>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/colorPrimary"
        app:itemTextColor="@drawable/selector"
        app:itemIconTint="@drawable/selector"
        app:menu="@menu/navigation"
        android:layout_alignParentBottom="true"
        app:labelVisibilityMode="labeled" />

</RelativeLayout>

JAVA

        BottomNavigationView bottomNavigationView = findViewById(R.id.navigation);
        bottomNavigationView.setSelectedItemId(R.id.navigation_one);
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.navigation_one:
                        return true;
                    case R.id.navigation_two:
                        startActivity(new Intent(getApplicationContext() ,Two.class));
                        overridePendingTransition(0,0);
                        finish();
                        return true;
                    case R.id.navigation_three:
                        startActivity(new Intent(getApplicationContext() ,Three.class));
                        overridePendingTransition(0,0);
                        finish();
                        return true;
                    case R.id.navigation_four:
                        startActivity(new Intent(getApplicationContext() ,Four.class));
                        overridePendingTransition(0,0);
                        finish();
                        return true;
                }
                return false;
            }
        });
shinsky Paul
  • 97
  • 10
  • You can find your answer in this link: [Hide/Show bottomNavigationView on Scroll](https://stackoverflow.com/questions/44777869/hide-show-bottomnavigationview-on-scroll) – Hamid Rasti Jun 22 '20 at 19:20
  • thanks @hamraa. I want to implement in the xml above as I dont want to change to coordinator layout for now. – shinsky Paul Jun 22 '20 at 19:25

1 Answers1

0

If you dont want to change to coordinator layout you can do this:

  • setOnScrollChangeListener for ScrollView to detect scrolling direction (up and down)
  • then in the onScrollChange method animate the bottomNavigationView to slide up and down (based on scrolling direction)
Hamid Rasti
  • 813
  • 1
  • 6
  • 16
  • Thanks again @hamraa Unfortunately `setOnScrollChangeListener` requires API 23 and above. Seems will have to try coordinator and revert – shinsky Paul Jun 23 '20 at 13:50