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
How to disable BottomNavigationView click and Touch?
Asked Answered
add your code here –
Tremendous
i just want to impliment, but do not know how, –
Division
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);
}
}
mBottomMenu.menu.iterator().forEach { it.isEnabled = enable } –
Sheenasheeny
How can I hide a particular tab for eg) say the home tab needs to be hidden in the landscape mode. –
Animality
Kotlin style one-liner:
bottom_navigation.menu.forEach { it.isEnabled = false }
Kotlin one-liner FTW! –
Yumuk
<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 }
i still can click and choose the item –
Division
bottomView.setOnClickListener(null); try this. –
Pinon
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
}
}
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);
}
}
}
}
You can do something like
bottomNavigation.menu.iterator().forEach { it.isEnabled = !error }
© 2022 - 2024 — McMap. All rights reserved.