BottomNavigationBar这个控件的使用之前已经写过,这里不再赘述,详情请参考BottomNavigationBar的使用。
目前成都创新互联公司已为近千家的企业提供了网站建设、域名、网站空间、网站托管维护、企业网站设计、吉安网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
下面直接上代码:
初始化及相关设置:
- mBottomNavigationBar = (BottomNavigationBar) view.findViewById(R.id.bottom_navigation_bar);
- mBottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC);
- mBottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
- mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.home_fill, getString(R.string.item_home)).setInactiveIconResource(R.drawable.home).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1))
- .addItem(new BottomNavigationItem(R.drawable.location_fill, getString(R.string.item_location)).setInactiveIconResource(R.drawable.location).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1))
- .addItem(new BottomNavigationItem(R.drawable.like_fill, getString(R.string.item_like)).setInactiveIconResource(R.drawable.like).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1))
- .addItem(new BottomNavigationItem(R.drawable.person_fill, getString(R.string.item_person)).setInactiveIconResource(R.drawable.person).setActiveColorResource(R.color.colorPrimary).setInActiveColorResource(R.color.black_1))
- .setFirstSelectedPosition(0)
- .initialise();
- mBottomNavigationBar.setTabSelectedListener(this);
- setDefaultFragment();
Tab的切换:
- @Override
- public void onTabSelected(int position) {
- FragmentTransaction beginTransaction = getFragmentManager().beginTransaction();
- switch (position) {
- case 0:
- if (mHomeFragment == null) {
- mHomeFragment = HomeFragment.newInstance(getString(R.string.item_home));
- }
- beginTransaction.replace(R.id.sub_content, mHomeFragment);
- break;
- case 1:
- if (mLocationFragment == null) {
- mLocationFragment = LocationFragment.newInstance(getString(R.string.item_location));
- }
- beginTransaction.replace(R.id.sub_content, mLocationFragment);
- break;
- case 2:
- if (mLikeFragment == null) {
- mLikeFragment = LikeFragment.newInstance(getString(R.string.item_like));
- }
- beginTransaction.replace(R.id.sub_content, mLikeFragment);
- break;
- case 3:
- if (mPersonFragment == null) {
- mPersonFragment = PersonFragment.newInstance(getString(R.string.item_person));
- }
- beginTransaction.replace(R.id.sub_content, mPersonFragment);
- }
- beginTransaction.commit();
- }
说明:这几篇文章没有过多的文字叙述,因为这些东西也不是很难,而且都是常用的,相信很多人都了如指掌了,多说亦是废话,直接上代码看的反而更清楚。
分享标题:Android底部导航栏实现(一)之BottomNavigationBar
网页地址:http://www.shufengxianlan.com/qtweb/news8/224308.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联