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();
- }
说明:这几篇文章没有过多的文字叙述,因为这些东西也不是很难,而且都是常用的,相信很多人都了如指掌了,多说亦是废话,直接上代码看的反而更清楚。
AI已经成为我们日常生活的一部分,这一点你无法否认。几乎来自所有不同行业的财...
【责任编辑: 七月 TEL:(010)68476606】 本文转载自网络,原文链接:...
尽管苹果在仅仅五个月前的2019年9月推出了iPhone 11三款机型,现在的传闻又称iPh...
前言 如果Crash堆栈,最后一个方法是在自己工程的源码,问题都比较好解决。但如...
PC微信和手机微信一直是我们使用最频繁的应用。 毕竟作为现在的国民级应用,几乎...
用户最想要什么?如何围绕内容打造可持续的互动生态?这正是本文想要与大家分享与...
DigiTimes 今天发布了一份报告,着重强调了苹果正建立一个完全由中国制造商组成...
1、ARP协议简介 在《IP协议》中我们讲解了IP地址相关内容,IP协议中包含了目的IP...
传统上,蜂窝无线接入网(RAN)使用的专有网络设备来自少数的网络设备制造商,但随...
针对外界谣传的首批千万5G用户被当作小白鼠,运营商已无情抛弃,联通、电信方面...