添加依赖
-
implementation 'com.android.support:design:26.1.0'
-
compile 'com.hjm:BottomTabBar:1.1.1'
布局
-
<com.hjm.bottomtabbar.BottomTabBar
-
android:id= "@+id/bottom_tab_bar"
-
android:layout_width= "match_parent"
-
android:layout_height= "match_parent"
-
xmlns:hjm= "http://schemas.android.com/apk/res-auto"
-
hjm:tab_img_height= "25dp"
-
hjm:tab_img_width= "25dp"
-
hjm:tab_isshow_divider= "true"
-
hjm:tab_padding_bottom= "2dp"
-
hjm:tab_selected_color= "#000000"
-
hjm:tab_unselected_color= "#989ea7"
-
>
-
</com.hjm.bottomtabbar.BottomTabBar>
//在主线程实现
-
//创建BottomTabBar控件
-
BottomTabBar bottomTabBar=findViewById(R.id.bottom_tab_bar);
-
//设置底部导航文字图片和Fragment
-
bottomTabBar.init(getSupportFragmentManager())
-
//第一个参数放文字,第二个参数放图片,第三个参数放Fragment
-
.addTabItem( "首页", R.drawable.bottom_shou,Fragment_Home.class)
-
.addTabItem( "关注", R.drawable.bottom_guanzhu, Fragment_Focus.class)
-
.addTabItem( "添加", R.drawable.jia2, Fragment3.class)
-
.addTabItem( "消息", R.drawable.bottom_xiaoxi, Fragment_information.class)
-
.addTabItem( "我的", R.drawable.bottom_wode, Fragment_my.class);
-
}