底部导航栏框架(BottomTabBarde使用)

添加依赖

  1. implementation 'com.android.support:design:26.1.0'
  2. compile 'com.hjm:BottomTabBar:1.1.1'

布局

  1. <com.hjm.bottomtabbar.BottomTabBar
  2. android:id= "@+id/bottom_tab_bar"
  3. android:layout_width= "match_parent"
  4. android:layout_height= "match_parent"
  5. xmlns:hjm= "http://schemas.android.com/apk/res-auto"
  6. hjm:tab_img_height= "25dp"
  7. hjm:tab_img_width= "25dp"
  8. hjm:tab_isshow_divider= "true"
  9. hjm:tab_padding_bottom= "2dp"
  10. hjm:tab_selected_color= "#000000"
  11. hjm:tab_unselected_color= "#989ea7"
  12. >
  13. </com.hjm.bottomtabbar.BottomTabBar>

//在主线程实现

  1. //创建BottomTabBar控件
  2. BottomTabBar bottomTabBar=findViewById(R.id.bottom_tab_bar);
  3. //设置底部导航文字图片和Fragment
  4. bottomTabBar.init(getSupportFragmentManager())
  5. //第一个参数放文字,第二个参数放图片,第三个参数放Fragment
  6. .addTabItem( "首页", R.drawable.bottom_shou,Fragment_Home.class)
  7. .addTabItem( "关注", R.drawable.bottom_guanzhu, Fragment_Focus.class)
  8. .addTabItem( "添加", R.drawable.jia2, Fragment3.class)
  9. .addTabItem( "消息", R.drawable.bottom_xiaoxi, Fragment_information.class)
  10. .addTabItem( "我的", R.drawable.bottom_wode, Fragment_my.class);
  11.         }

猜你喜欢

转载自blog.csdn.net/qq_42447950/article/details/81025613