您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關Android中怎么利用BottomNavigationBar實現(xiàn)底部導航欄,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
初始化及相關設置:
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實現(xiàn)底部導航欄,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學到更多知識。更多詳情敬請關注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。