Search code examples
androidandroid-studioandroid-layoutbottomnavigationview

How to add Bottom Navigation View in all the activities in android app


I am developing an android app it has many activities and I decided to use the bottom navigation view to make the user interface more attractive. But I have a problem that I need to put this bottom navigation view in all the activity and for this, I need to put the view in every XML file and also needs to bind that view in every class file. So is there any way that I need to create the bottom navigation view one time and it shows in all the activity and no need to bind every time in java? And it shows up in all the activities.


Solution

  • Option 1. Make NavigationActivity and change all Activities to Fragments. Then you can use all Activities in ViewPager

    Option 2. If you use ViewBinding (what you probably should) make NavigationBottomView as own class and use own layout for it. Then iin each activity you need include in xml and create new Instance of your NavigationBottomView