超简单,几行代码搞定Android底部导航栏

                                   超简单,几行代码搞定Android底部导航栏

第一步:加依赖

compile 'com.hjm:BottomTabBar:1.0.0'

第二步:布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:hjm="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffF6F2ED"
    tools:context="test.com.dianshang.MainActivity">

<com.hjm.bottomtabbar.BottomTabBar
    android:id="@+id/bottom_tab_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    hjm:tab_divider_background="#FF0000"
    hjm:tab_divider_height="5dp"
    hjm:tab_font_size="6sp"
    hjm:tab_img_font_padding="0dp"
    hjm:tab_img_height="30dp"
    hjm:tab_img_width="30dp"
    hjm:tab_isshow_divider="true"
    hjm:tab_padding_bottom="5dp"
    hjm:tab_padding_top="8dp"
    hjm:tab_selected_color="#000000"
    hjm:tab_unselected_color="@color/colorPrimary" />
第三步:Activity类写主要代码
          //找控件
BottomTabBar bottomTabBar = (BottomTabBar) findViewById(R.id.bottom_tab_bar);
bottomTabBar.init(getSupportFragmentManager())
        .setImgSize(50,50)
        .setFontSize(8)
        .setTabPadding(4,6,10)
        .setChangeColor(Color.DKGRAY,Color.RED)
        .addTabItem("首页", R.mipmap.bav, OneFragment.class)
        .addTabItem("分类", R.mipmap.bat, TwoFragment.class)
        .addTabItem("发现", R.mipmap.axe, ThreeFragment.class)
        .addTabItem("购物车", R.mipmap.bar, FourFragment.class)
        .addTabItem("我的", R.mipmap.a_k, FiveFragment.class)
        .setTabBarBackgroundColor(Color.WHITE) .isShowDivider(false);

也很简单,是吧。
 这里简单的提一句,这个init ( getSupportFragmentManager() )方法一定要第一个
调用,没有这个初始化,后边什么也做不了。


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值