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,
12345 <android.support.design.widget.BottomNavigationViewandroid: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
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"><itemandroid:id="@+id/action_home"android:enabled="true"android:icon="@drawable/home"android:title="Home"app:showAsAction="ifRoom" /><itemandroid:id="@+id/action_navigation"android:enabled="true"android:title="Menu"android:icon="@drawable/menu"app:showAsAction="ifRoom" /><itemandroid:id="@+id/action_camera"android:enabled="true"android:title="Camera"android:icon="@drawable/camera"app:showAsAction="ifRoom" /><itemandroid:id="@+id/action_cart"android:enabled="true"android:title="Cart"android:icon="@drawable/cart"app:showAsAction="ifRoom" /><itemandroid:id="@+id/action_profile"android:enabled="true"android:title="Profile"android:icon="@drawable/user"app:showAsAction="ifRoom" /></menu>
Step 3: Add navigation Listener,
1234567891011121314151617181920212223242526 bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {@Overridepublic 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.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.