Android底部导航栏的实现

总结:
最快制作页面底部的四个RadioButto
(1)先将compile 'com.hjm:BottomTabBar:1.1.1' 导入build.gradle。
在布局文件里面导入<com.hjm.bottomtabbar.BottomTabBar>把宽高全部都为充满。在创建一个布局fragment方便后面进行使用,里面什么都不用写。

(2)在主类里面创建一个方法init(),
将下面代码直接粘贴,复制
[html] view plain copy
  1.   
[java] view plain copy
  1. bottomTabBar = (BottomTabBar) findViewById(R.id.bottomTabBar);  
  2. /底部导航栏  
  3.        bottomTabBar.init(getSupportFragmentManager())  
  4.                .setImgSize(3535)  
  5.                .setFontSize(0)  
  6.                .setChangeColor(Color.RED, Color.GRAY)  
  7.                .addTabItem("首页", R.mipmap.ic_nav_home_press, R.mipmap.ic_nav_home, Fragment1.class) 前面第一个是点击后的图片,第二个是点击前的图片  
  8.                .addTabItem("分类", R.mipmap.ic_nav_class_press, R.mipmap.ic_nav_class, Fragment2.class)  
  9.                .addTabItem("购物车", R.mipmap.ic_nav_cart_press, R.mipmap.ic_nav_cart, Fragment3.class)  
  10.                .addTabItem("个人", R.mipmap.ic_nav_user_press, R.mipmap.ic_nav_user, Fragment4.class)  
  11.                .isShowDivider(false);  


最后创建4个fragment,在frangment重写onCreateView的方法,(特别注意导包一定要导android.support.v4.app.Fragment)
[java] view plain copy
  1. View view=inflater.inflate(R.layout.fragment,container,false);  
  2. return view;  

猜你喜欢

转载自blog.csdn.net/ediao_nvhai/article/details/80074407