美文网首页
开源框架:底部导航栏 BottomNavigation

开源框架:底部导航栏 BottomNavigation

作者: 幻梦泽 | 来源:发表于2017-06-03 16:48 被阅读0次

    1.github地址

    https://github.com/Ashok-Varma/BottomNavigation

    2.Gradle导入

    compile 'com.ashokvarma.android:bottom-navigation-bar:1.4.1'

    3.使用

    1.xml布局文件

        <com.ashokvarma.bottomnavigation.BottomNavigationBar
            android:id="@+id/bottomBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            app:bnbMode="mode_fixed"
            app:bnbActiveColor="#262626"
            app:bnbInactiveColor="#888888" />
    

    2.dimens.xml中

    <resources>
        <!-- BottomNavigation配置 -->
        <dimen name="fixed_height">56dp</dimen> <!-- 高度 -->
        <dimen name="fixed_icon_grid">24dp</dimen> <!-- icon大小 -->
        <dimen name="fixed_height_top_padding_inactive">3dp</dimen> <!-- 未选中时顶部padding -->
        <dimen name="fixed_height_top_padding_active">3dp</dimen> <!-- 选中时顶部padding -->
        <dimen name="fixed_height_bottom_padding">5dp</dimen> <!-- 底部padding -->
        <dimen name="fixed_label_active">12sp</dimen> <!-- 选中字体大小 -->
        <dimen name="fixed_label_inactive">12sp</dimen> <!-- 未选中字体大小 -->
        <item name="fixed_label_active_to_inactive_ratio" format="float" type="dimen">1</item> <!-- 默认文字大小缩放比率 -->
    </resources>
    

    3.java代码

            bottomBar = (BottomNavigationBar) findViewById(R.id.bottomBar);
            bottomBar.addItem(new BottomNavigationItem(R.drawable.ic_home_selected_24dp,"首页")
                            .setInactiveIconResource(R.drawable.ic_home_unselected_24dp));
            bottomBar.addItem(new BottomNavigationItem(R.drawable.ic_favorite_selected_24dp,"收藏")
                    .setInactiveIconResource(R.drawable.ic_favorite_unselected_24dp));
            bottomBar.addItem(new BottomNavigationItem(R.drawable.ic_material_selected_24dp,"资料")
                    .setInactiveIconResource(R.drawable.ic_material_unselected_24dp));
            bottomBar.initialise();
    

    相关文章

      网友评论

          本文标题:开源框架:底部导航栏 BottomNavigation

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