ibrahimsn98 / SmoothBottomBar

A lightweight Android material bottom navigation bar library
MIT License
1.95k stars 253 forks source link

setCurrentItem method missing #57

Closed ketanbhardwaj closed 3 years ago

ketanbhardwaj commented 4 years ago

setCurrentItem method is missing from the SmoothBottomBar class. This is required if I want to manually switch the tab programmatically. Similarly getCurrentItem method is missing as well.

Please provide some workaround for this.

Thanks

imdineshsingh commented 3 years ago

I overcome this issue by adding my own method for set and getCurrentItem.

ibrahimsn98 commented 3 years ago

@ketanbhardwaj You can set an index value to itemActiveIndex.

vedprakashsah1998 commented 3 years ago

int currentItem; ` binding.bottomBar.setOnItemSelectedListener(i -> { currentItem = i; if (i == 0) { navController.navigate(R.id.fragment_all_user); } else if (i == 1) { navController.navigate(R.id.topic_fragment); } else if (i == 2) { navController.navigate(R.id.notification); } else if (i == 3) { navController.navigate(R.id.profile_fragment); }

        return true;
    });`

` @Override public void onBackPressed() { FragmentManager fm = getSupportFragmentManager(); fm.popBackStack(); if (currentItem == 0) { super.onBackPressed(); finish(); } else { currentItem--; binding.bottomBar.setItemActiveIndex(currentItem); }

}`