Beginner’s Guide for Android Jetpack’s Navigation component

Photo by Joseph Barrientos on Unsplash

Android Jetpack’s Navigation component is a better approach in Android to navigate across, into, and back out from the different pieces of content within your app. This post shows you how to set up and work with the Navigation component.

For using the Navigation component we must first add the dependency in our Android project, you can get the dependency here.

Now after we have added our dependency, we must add a new resource file in our Android project. Let’s name our file nav_graph and it must be of type Navigation.

Photo by Croissant on Unsplash

In this post, we are going to learn how we can customize the style of the overflow menu of the toolbar.

Creating Style

First of all, let’s create a style for our overflow menu. Here, I am going to create a style named CustomPopupMenuStyle and add some basic attributes related to altering the text style.

Adding style to the toolbar

Now, as our style has been created let’s add it to our toolbar.

Photo by Emile Perron on Unsplash

In this post, we are going to learn how to style AutoCompleteTextView to look alike Spinner. It will have both a dropdown feature like Spinner and a typing feature to help filter suggestions.

Adding AutoCompleteTextView in XML

Firstly we should add a dropdown icon at the end of the view. For that, we can simply use the android:drawableEnd attribute in our XML layout.

Photo by Tim Mossholder on Unsplash

Creating Spinner and Custom Class

First of all, we must define Spinner in our XML layout.

Now let’s create a custom object which we are going to use in our Spinner.

As we have created a custom class, let’s define a variable for Spinner in our Kotlin code. Since we need to display data in our Spinner using an Adapter let’s also define an ArrayAdapter variable that holds our custom object.

Now, we should instantiate these variables in onViewCreated() if it is a fragment or onCreate() if it is an activity.

Populate Spinner with Sample Data

Also, let’s prepare a list of custom objects with sample data…

A Better Approach to Send Data Between Fragments

Photo by Clarissa Watson on Unsplash

In this post, we will be learning how to use the Safe-Args feature which has been included in the Android Jetpack’s Navigation Component. This post is an extension to my previous post Getting Started with the Navigation Component, even if you haven’t checked my previous post you can continue reading but if you are unfamiliar with the Navigation Component then you should definitely check it out.

Things to remember before passing data between destinations

Before jumping straight into how we are going to use Safe-Args in the Navigation component, we should remember that in general, we should strongly prefer passing only the minimal amount of data between destinations…

Shrayan Bajracharya

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store