加载API结果时禁用BottomNavigationView

时间:2018-01-08 07:45:07

标签: android android-layout bottomnavigationview

我想在加载API结果时禁用对BottomNavigationView的点击。我已使用以下代码禁用:

if (bottomNavigationView != null) {
        bottomNavigationView.setClickable(!showLoading);
        bottomNavigationView.setFocusable(!showLoading);
        bottomNavigationView.setEnabled(!showLoading);
        if (showLoading) {
            bottomNavigationView.setOnNavigationItemSelectedListener(null);
        } else {
            bottomNavigationView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
        }
    }

这样做会阻止调用NavigationItemSelectedListener。这很好。

问题是,它仍然选择菜单项并根据选择器更改颜色。

TIA

2 个答案:

答案 0 :(得分:0)

数据hide时只需bottomNavigation isloading()。如果视图已停用,则无法显示视图,或者您可以animations执行某些translations from bottom数据正在加载..

答案 1 :(得分:0)

想出来:

这就是我的选择器的样子

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/grey3" android:state_checked="false" />
<item android:color="@color/blue" />
</selector>

将我的所有菜单项添加到论坛。摆脱我以前的代码禁用,现在使用下面的单行代码:

if (bottomNavigationView != null) {
            bottomNavigationView.getMenu().setGroupEnabled(R.id.group1, !showLoading);
//            bottomNavigationView.setClickable(!showLoading);
//            bottomNavigationView.setFocusable(!showLoading);
//            bottomNavigationView.setEnabled(!showLoading);
//            if (showLoading) {
//                bottomNavigationView.setOnNavigationItemSelectedListener(null);
//            } else {
//                bottomNavigationView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
//            }
        }

在布局xml中:

<android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/grey0"
        app:elevation="2dp"
        app:layout_anchorGravity="bottom"
        app:menu="@menu/main_nav"
        app:itemTextColor="@color/bottom_nav"
        app:itemIconTint="@color/bottom_nav" />

最后2行是造成视觉差异的原因。

希望这有助于某人。

干杯