BottomTabBar的使用

来源:互联网 发布:人工智能接口 编辑:程序博客网 时间:2024/06/07 15:50

最快制作页面底部的四个RadioButto

(1)先将compile 'com.hjm:BottomTabBar:1.1.1' 导入build.gradle。

在布局文件里面导入<com.hjm.bottomtabbar.BottomTabBar>把宽高全部都为充满。在创建一个布局fragment方便后面进行使用,里面什么都不用写。


(2)在主类里面创建一个方法init(),

将下面代码直接粘贴,复制

 bottomTabBar = (BottomTabBar) findViewById(R.id.bottomTabBar);

//底部导航栏

        bottomTabBar.init(getSupportFragmentManager())

                .setImgSize(35, 35)

                .setFontSize(10)

                .setChangeColor(Color.RED, Color.GRAY)

                .addTabItem("首页", R.mipmap.ic_nav_home_press, R.mipmap.ic_nav_home, Fragment1.class) 前面第一个是点击后的图片,第二个是点击前的图片

                .addTabItem("分类", R.mipmap.ic_nav_class_press, R.mipmap.ic_nav_class, Fragment2.class)

                .addTabItem("购物车", R.mipmap.ic_nav_cart_press, R.mipmap.ic_nav_cart, Fragment3.class)

                .addTabItem("个人", R.mipmap.ic_nav_user_press, R.mipmap.ic_nav_user, Fragment4.class)

                .isShowDivider(false);

最后创建4个fragment,在frangment重写onCreateView的方法,(特别注意导包一定要导android.support.v4.app.Fragment)

View view=inflater.inflate(R.layout.fragment,container,false);

return view;

原创粉丝点击