The material design team at Google defines the functionality of bottom navigation bars in Android as follows:
Bottom navigation bars make it easy to explore and switch between top-level views in a single tap.
Tapping on a bottom navigation icon takes you directly to the associated view or refreshes the currently active view.
According to the official material design guidelines for the bottom navigation bar, it should be used when your app has:
three to five top-level destinations
destinations requiring direct access
An example of a popular app that implements the bottom navigation bar is the Google+ Android app from Google, which uses it to navigate to different destinations of the app. You can see this yourself by downloading the Google+ app from Google Play store (if you don’t already have it on your device). The following screenshot is from the Google+ app displaying a bottom navigation bar.
In this post, you’ll learn how to display menu items inside a bottom navigation bar in Android. We’ll use the BottomNavigationView API to perform the task. For an additional bonus, you’ll also learn how to use the Android Studio templates feature to quickly bootstrap your project with a bottom navigation bar.
A sample project (in Kotlin) for this tutorial can be found on our GitHub repo so you can easily follow along.
Prerequisites
To be able to follow this tutorial, you’ll need:
Android Studio 3.0 or higher
Kotlin plugin 1.1.51 or higher
1. Create an Android Studio Project
Fire up Android Studio and create a new project (you can name it BottomNavigationDemo) with an empty activity called MainActivity. Make sure to also check the Include Kotlin support check box.
2. Adding the BottomNavigationView
To begin using BottomNavigationView in your project, make sure you import the design support and also the Android support artifact. Add these to your module’s build.gradle file to import them.
Also, visit your res/layout/activlty_main.xml file to include the BottomNavigationView widget. This layout file also includes a ConstraintLayout and a FrameLayout. Note that the FrameLayout will serve as a container or placeholder for the different fragments that will be placed on it anytime a menu item is clicked in the bottom navigation bar. (We’ll get to that shortly.)
Here we have created a BottomNavigationView widget with the id navigationView. The official documentation says that:
BottomNavigationView represents a standard bottom navigation bar for application. It is an implementation of material design bottom navigation.
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 application has three to five top-level destinations.
The important attributes you should take note of that were added to our BottomNavigationView are:
app:itemBackground: this attribute sets the background of our menu items to the given resource. In our case, we just gave it a background colour.
app:itemIconTint: sets the tint which is applied to our menu items’ icons.
app:itemTextColor: sets the colours to use for the different states (normal, selected, focused, etc.) of the menu item text.
To include the menu items for the bottom navigation bar, we can use the attribute app:menu with a value that points to a menu resource file.
Here is the res/menu/navigation.xml menu resource file:
Here we have defined a Menu using the
Android SDK
Build a Music App With an Android App Template
Chike Mgbemena
App Templates
15 Best Android App Templates of 2017
Nona Blackman
Android SDK
Android From Scratch: Using REST APIs
Ashraff Hathibelagal
Android SDK
How to Code a Navigation Drawer for an Android App
This website uses cookies to improve your experience. AcceptRead More
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.