我可以禁止在特定逻辑的BottomNavigationView项目中移动吗?
问题描述:
目前我有像这个 -我可以禁止在特定逻辑的BottomNavigationView项目中移动吗?
mBottomNav.setOnNavigationItemSelectedListener(
......
switch (item.getItemId()) {
case R.id.actionUser:
if(userLoggedIn) {
mHomePresenter.btnUser();
}
else {
showLongToast("User Not Logged In");
}
break;
});
逻辑其他部分的实现,我将显示敬酒消息,无论是我想要的BottomNavigationView转移也没有菜单图标的颜色变化。
如何才能在这个特定的部分实现这样的逻辑?所有其他菜单项将保持默认的切换逻辑。
答
那么答案很简单,对于条件你要过渡到发生,因为你不想返回false
以你的代码考虑条件返回true
,它应该是
mBottomNav.setOnNavigationItemSelectedListener(
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.actionUser:
if(userLoggedIn) {
mHomePresenter.btnUser();
return true;
}
else {
showLongToast("User Not Logged In");
return false;
}
}
});
如果检查导航选择监听器的文件,你可以看到
/**
* Listener for handling selection events on bottom navigation items.
*/
public interface OnNavigationItemSelectedListener {
/**
* Called when an item in the bottom navigation menu is selected.
*
* @param item The selected item
*
* @return true to display the item as the selected item and false if the item should not
* be selected. Consider setting non-selectable items as disabled preemptively to
* make them appear non-interactive.
*/
boolean onNavigationItemSelected(@NonNull MenuItem item);
}
嗨法蒂玛 你能否提供更多信息?目前尚不清楚。如果你能提供一些运行的例子,这将是非常好的。 –
我已经有了一个解决方案。见下面接受的答案。感谢你的关心! @ShravanJain – Farwa
Awesome Yrr .... :) –