

A menu resource file containing the options to be displayed within the navigation drawer.An instance of the NavigationView component embedded as a child of the DrawerLayout.An instance of the DrawerLayout component.Figure 50-1, for example, shows the navigation drawer built into the Google Play app:Ī navigation drawer is made up of the following components: Implements NavigationView.The navigation drawer is a panel that slides out from the left of the screen and contains a range of options available for selection by the user, typically intended to facilitate navigation to some other part of the application. Public class MainActivity extends AppCompatActivity Note: Nested menu items are possible inside the app:menus layout The MainActivity.java is given below package The android:checkable attribute is used for setting the checkable behaviour for individual items. all : All items can be checked (checkboxes).single : Only one item from the group can be checked.The android:checkableBehavior xml attribute is defined for the entire group and it takes either of the three values listed below. The default headerLayout and the menu for the NavigationView are listed below: nav_header_main.xml The content_main.xml layout is listed below: The app_bar_main.xml layout consists of a CoordinatorLayout that holds a ToolBar, a FloatingActionButton and a content_main.xml layout(which displays a basic ‘Hello World’ TextView). Note: The above DrawerLayout is the layout that holds the navigation drawer content and our app’s content. The activity_main.xml is the layout for the MainActivity. Let’s look into the Project Structure of the inbuilt NavigationView template.


NavigationView is generally placed inside a DrawerLayout. With the introduction of a NavigationView all we require is to inflate the items using menu resources that we’ll see soon. NavigationDrawer required us to implement the items using a ListView/ RecyclerView by implementing a custom Adapter. NavigationView is a better and easier to implement alternative to a Navigation Drawer. We have already implemented a Navigation Drawer in this tutorial and it was tiresome to code.

Here, we’ll learn to style it such that it opens from right to left too.
#Android navigation drawer set icon android#
In this tutorial, we’ll discuss and implement a NavigationView in our android application.
