i want to implement behavior on certain condition the bottom view is unable to click, i want to make if bottom view item being click it does not navigate to that item but still stay at the current item
Asked
Active
Viewed 1.7k times
14
-
add your code here – Abdul Waheed Oct 03 '17 at 08:06
-
i just want to impliment, but do not know how, – Muhammad Aiman Bin Kamal Oct 03 '17 at 08:09
6 Answers
26
You can disable menu items if you want to disable bottom navigation view
private void enableBottomBar(boolean enable){
for (int i = 0; i < mBottomMenu.getMenu().size(); i++) {
mBottomMenu.getMenu().getItem(i).setEnabled(enable);
}
}

ysfcyln
- 2,857
- 6
- 34
- 61
-
-
How can I hide a particular tab for eg) say the home tab needs to be hidden in the landscape mode. – sejn Jan 06 '22 at 11:24
11
Kotlin style one-liner:
bottom_navigation.menu.forEach { it.isEnabled = false }

Sai
- 15,188
- 20
- 81
- 121
2
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:contextClickable="false"/>
Try this code.it Disables the click.
Dynamicaly using Java pr Kotlin you can disable click.
bottomView.setEnabled(false);
bottomView.setFocusable(false);
bottomView.setFocusableInTouchMode(false);
bottomView.setClickable(false);
bottomView.setContextClickable(false);
bottomView.setOnClickListener(null);
setting onClick Listener to Null helps to Disable click events
bottomView.menu.forEach { it.isEnabled = false }

Tomin B Azhakathu
- 2,656
- 1
- 19
- 28
1
You can set the touch listeners of its subviews. Example using android-ktx:
bottomNav.children.forEach {
(it as? ViewGroup)?.children?.forEach {
it.setOnTouchListener { _, _ -> true } // or null to enable touch again
}
}

Boni2k
- 3,255
- 3
- 23
- 27
0
public class CustomBottomNavigationView extends BottomNavigationView {
...
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
ViewGroup menuView = (ViewGroup) getChildAt(0);
if (menuView != null) {
for (int i = 0; i < menuView.getChildCount(); i++) {
menuView.getChildAt(i).setEnabled(enabled);
}
}
}
}

Anton Kaliturin
- 147
- 1
- 6
0
You can do something like
bottomNavigation.menu.iterator().forEach { it.isEnabled = !error }

Amaury Ricardo
- 267
- 2
- 5