Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report