超简单,几行代码搞定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() )方法一定要第一个
调用,没有这个初始化,后边什么也做不了。