Search code examples
javaandroidbottomnavigationview

BottomNavigationView no Animation


My BottomNavigationView has no animation when changing items. I saw some videos on YouTube, and they have everything the same. And you see the animation well. What do I have to add? Thank you.


Solution

  • You can use a ViewPager to store your items (fragments). Then for each bottom navigation item, set the viewpager's current item to have the animation effect.

    mNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            // switch ViewPager items for each bottom navigation item
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    mViewPager.setCurrentItem(0);
                    return true;
                case R.id.navigation_dashboard:
                    mViewPager.setCurrentItem(1);
                    return true;
                case R.id.navigation_notifications:
                    mViewPager.setCurrentItem(2);
                    return true;
            }
            return false;
        }
    });