美文网首页
BottomNavigationView 基础属性及应用

BottomNavigationView 基础属性及应用

作者: 醉红尘_acb4 | 来源:发表于2020-09-21 11:58 被阅读0次

    app:labelVisibilityMode="labeled" // 标签可见性模式

    app:itemBackground="@null"   // 取消item点击切换时背景会有水波效果

    mBottomNavigationView.setItemIconTintList(null);   // 不使用图标默认变色

    添加角标

    /*角标https://github.com/qstumn/BadgeView#how-to-use*/

    implementation'q.rorbin:badgeview:1.1.3'

    /**

        * BottomNavigationView显示角标

        *

        * @param viewIndex  tab索引

        * @param showNumber 显示的数字,小于等于0是将不显示

        */

        private void showBadgeView(int viewIndex, int showNumber) {

            // 具体child的查找和view的嵌套结构请在源码中查看

            // 从bottomNavigationView中获得BottomNavigationMenuView

            BottomNavigationMenuView menuView = (BottomNavigationMenuView) bnve.getChildAt(0);

            // 从BottomNavigationMenuView中获得childview, BottomNavigationItemView

            if (viewIndex < menuView.getChildCount()) {

                // 获得viewIndex对应子tab

                View view = menuView.getChildAt(viewIndex);

                // 从子tab中获得其中显示图片的ImageView

                View icon = view.findViewById(com.google.android.material.R.id.icon);

                // 获得图标的宽度

                int iconWidth = icon.getWidth();

                // 获得tab的宽度/2

                int tabWidth = view.getWidth() / 2;

                // 计算badge要距离右边的距离

                int spaceWidth = tabWidth - iconWidth;

                // 显示badegeview

                qBadgeView.bindTarget(view) /*绑定目标*/

                        .setGravityOffset(spaceWidth, 3, false) /*设置重力偏移*/

                        .setBadgeNumber(showNumber); /*设置徽章编号*/

            }

        }

    相关文章

      网友评论

          本文标题:BottomNavigationView 基础属性及应用

          本文链接:https://www.haomeiwen.com/subject/gugxmxtx.html