BottomNavigationView is the best option for navigation in android. It makes life easier for a user to switch between multiple activities and fragments. It’s really a pain in the butt to use an android app without having proper navigation. At GFG, we have already shared an article with you on BottomNavigationView. If you are new or don’t know that what is BottomNavigationView or want to implement it in your app then please refer to this BottomNavigationView in Android.
We all are using android apps in our daily life. If you will observe carefully, you will found that an application with a better user-interface gets a heart from the user. He will love using that application and will come again and again. For creating better and professional user interfaces you have to take care of these small things. When a BottomNavigationView will show and hide on scrolling it will look much more professional and practical. You have also seen in LinkedIn, that how it’s BottomNavigationView shows and hide on scrolling. Do you also not want to implement it in BottomNavigationView of your own app. In this article, we are going to discuss how to implement this type of behavior in our android app. After going through this article, and understanding the logic you will be able to use it everywhere.
Step by Step Implementation
A sample GIF is given below to get an idea about what we are going to do in this article. This is a language-independent tutorial, the steps will be the same for Java and Kotlin.
Step 1: Open an existing project which has BottomNavigationView and you want to work on it. If you haven’t created it yet then you can always refer to this BottomNavigationView in Android and create it. You may also clone this GitHub project for implementation. And we have used this project as an example in this article.
Note: Please refer to this article to clone Android Project from GitHub in Android Studio.
Step 2: Then navigate to the Layout resource File on which you have used the BottomNavigationView. For Example, we have used it in the activity_home.xml file with RecyclerView.
Step 3: Now make sure that the parent layout for that layout resource file is CordinatorLayout because this behavior will not work in any other type of layout. It will only work in CordinatorLayout.
Note: CordinatorLayout is an advanced layout in android, It has much more interesting functionalities. While you will be dealing with the complex UI’s in android, then you can do it more efficiently in CordinatorLayout. You can read more about the CordinatorLayout from here.
Step 4: Now, In BottomNavigationView add an attribute like this.
Step 5: Try running your application on an emulator or a physical device. In this sample project, we have used a RecyclerView with BottomNavigationView. You can do the same with ScrollView or any other object in android.
Share your thoughts in the comments
Please Login to comment...