Skip to content

Files

Latest commit

f5fffac · Aug 14, 2024

History

History
186 lines (130 loc) · 5.14 KB

README.zh-cn.md

File metadata and controls

186 lines (130 loc) · 5.14 KB

BottomNavigationEx

version MIT License api 14+

一个增强BottomNavigationView的android库。(BottomNavigationViewEx(已废弃)的延续版本)

依赖

Gradle

  1. ex库

    implementation 'io.github.clistery:bottomnavigationex-ex:x.x.x'
  2. 基于 material 版本选择对应的版本

    • material1.10.x

      implementation 'io.github.clistery:bottomnavigationex-110x:x.x.x'
    • material1.9.x

      implementation 'io.github.clistery:bottomnavigationex-19x:x.x.x'
    • material1.8.x

      implementation 'io.github.clistery:bottomnavigationex-18x:x.x.x'
    • material1.7.x

      implementation 'io.github.clistery:bottomnavigationex-17x:x.x.x'
    • material1.6.x

      implementation 'io.github.clistery:bottomnavigationex-16x:x.x.x'
    • material1.5.x

      implementation 'io.github.clistery:bottomnavigationex-15x:x.x.x'
    • material1.4.x

      implementation 'io.github.clistery:bottomnavigationex-14x:x.x.x'
    • material1.3.x

      implementation 'io.github.clistery:bottomnavigationex-13x:x.x.x'
  3. gradle.properties 中添加如下配置

    android.useAndroidX=true
    android.enableJetifier=true

使用

  • xml 布局中添加自定义控件

    <com.yh.bottomnavigationex.BottomNavigationViewEx
        android:id="@+id/bnve"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        app:itemIconTint="@color/selector_item_color"
        app:itemTextColor="@color/selector_item_color"
        app:menu="@menu/menu_navigation_with_view_pager" />
  • Activity 中绑定控件

    BottomNavigationViewEx bnve = (BottomNavigationViewEx) findViewById(R.id.bnve);
  • 禁止所有动画效果

    bnve.enableAnimation(false);
    bnve.enableLabelVisibility(false);
    bnve.enableItemHorizontalTranslation(false);
  • 自定义图标和文本大小

    bnve.setIconSize(widthDp, heightDp);
    bnve.setTextSize(sp);
  • 和 ViewPager 绑定

    // set adapter
    adapter = new VpAdapter(getSupportFragmentManager(), fragments);
    bind.vp.setAdapter(adapter);
    
    // binding with ViewPager
    bind.bnve.setupWithViewPager(bind.vp);
  • 和 ViewPager2 绑定

    // set adapter
    adapter = new Vp2Adapter(getSupportFragmentManager());
    bind.vp.setAdapter(adapter);
    
    // binding with ViewPager
    bind.bnve.setupWithViewPager2(bind.vp);
  • 添加带数字的小红点

    BadgeDrawable bd = bind.bnve.getRealView().getOrCreateBadge(R.id.i_friends);
    bd.setNumber(1);
    bd.setHorizontalOffset(12);
    bd.setVerticalOffset(2);
  • 动态配置菜单项

    val menuCount: Int = max((Math.random() * 30).toInt(), 1)
    
    bnve.configDynamic(menuCount) { menu, index ->
        menu.add(0, index, index, "menu${index}")
            .setIcon(R.drawable.ic_favorite_black_24dp)
    }
  • 通过 getRealView 获取到原始 BottomNavigationView 的用法请参考官方文档

  • 其他更多的用法,请参考demo。

License

MIT License

Copyright (c) 2022 clistery

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.