Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use BottomNavigationBar to realize the bottom Navigation Bar in Android

Shulou Source: shulou.com Published: 2022-05-31 23:50:29 10月29日 Update

This article introduces the relevant knowledge of "how to use BottomNavigationBar to achieve the bottom navigation bar in Android". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Initialization and related settings:

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) .setInActiveColorResource (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) .initi alise () MBottomNavigationBar.setTabSelectedListener (this); setDefaultFragment ()

Switching of 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 () } "how to use BottomNavigationBar in Android to achieve the bottom navigation bar" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Bottom navigation content more knowledge practical learning next dilemma reality situation article case editing website industry process high quality switching learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS Huawei OPPO Reno vpn