Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Updated 22 May 2017
In this blog, we have learned how to add the bottom menu using BottomNavigationView.
Bottom navigation bars make it easy for users to explore and switch between top-level views in a single tap. It should be used when the application has three to five top-level destinations.
Step 1: Add the below layout,
<android.support.design.widget.BottomNavigationView android:id="@+id/bottomNavigation" android:layout_width="match_parent" android:layout_height="wrap_content" design:menu="@menu/navigation_items" /> 12345 <android.support.design.widget.BottomNavigationView android:id="@+id/bottomNavigation" android:layout_width="match_parent" android:layout_height="wrap_content" design:menu="@menu/navigation_items" />
Step 2: Make the navigation_items.xml in menu directory
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_home" android:enabled="true" android:icon="@drawable/home" android:title="Home" app:showAsAction="ifRoom" /> <item android:id="@+id/action_navigation" android:enabled="true" android:title="Menu" android:icon="@drawable/menu" app:showAsAction="ifRoom" /> <item android:id="@+id/action_camera" android:enabled="true" android:title="Camera" android:icon="@drawable/camera" app:showAsAction="ifRoom" /> <item android:id="@+id/action_cart" android:enabled="true" android:title="Cart" android:icon="@drawable/cart" app:showAsAction="ifRoom" /> <item android:id="@+id/action_profile" android:enabled="true" android:title="Profile" android:icon="@drawable/user" app:showAsAction="ifRoom" /> </menu> 12345678910111213141516171819202122232425262728293031323334 <?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_home" android:enabled="true" android:icon="@drawable/home" android:title="Home" app:showAsAction="ifRoom" /> <item android:id="@+id/action_navigation" android:enabled="true" android:title="Menu" android:icon="@drawable/menu" app:showAsAction="ifRoom" /> <item android:id="@+id/action_camera" android:enabled="true" android:title="Camera" android:icon="@drawable/camera" app:showAsAction="ifRoom" /> <item android:id="@+id/action_cart" android:enabled="true" android:title="Cart" android:icon="@drawable/cart" app:showAsAction="ifRoom" /> <item android:id="@+id/action_profile" android:enabled="true" android:title="Profile" android:icon="@drawable/user" app:showAsAction="ifRoom" /></menu>
Step 3: Add navigation Listener,
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.action_home: break; case R.id.action_navigation: mDrawerLayout.openDrawer(GravityCompat.START); break; case R.id.action_camera: onCLickOpenCamera(); break; case R.id.action_cart: Intent menuIntent = new Intent(MainActivity.this, Cart.class); startActivity(menuIntent); break; case R.id.action_profile: Intent intent = new Intent(MainActivity.this, DashboardActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); break; } return false; } }); 1234567891011121314151617181920212223242526 bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.action_home: break; case R.id.action_navigation: mDrawerLayout.openDrawer(GravityCompat.START); break; case R.id.action_camera: onCLickOpenCamera(); break; case R.id.action_cart: Intent menuIntent = new Intent(MainActivity.this, Cart.class); startActivity(menuIntent); break; case R.id.action_profile: Intent intent = new Intent(MainActivity.this, DashboardActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); break; } return false; } });
Thanks maybe this blog is needful for you.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.