Android Navigation


Android Navigation Widgets Types and Tutorial.

5 Android Navigation Widgets

Let's look at some examples.

Android ActionBar Tutorial.

Android BottomNavigation Tutorial.

Menus have traditionally been the way to navigation.

Nowadays more and more navigation facilities like Tabs, ViewPager and BottomNavigationBar are available.

Advantages of Menus

However, menus are probably still the easiet and most popular and advantageous. This is because of the following:

  1. They are easy to use for users with respect to navigation.

  2. Menus can confine more menu items in a small space compared to other navigation utilities like the navigationview, tabs and bottom bar.

  3. Menus are typically easy to customize as we represent them via XML in many cases.

  4. It's relatively easier to apply animations to menu items than other navigation components.

Android NavigationView Tutorial.

A Toolbar is a generalization of action bars for use within application layouts. Traditionally, an actionbar has always part of an Activity's opaque window decor controlled by the framework.

Toolbar on the other hand may be placed at any arbitrary level of nesting within a view hierarchy.

ToolBar API Definition

ToolBar derives from ViewGroup and was added in version 25.1.0.

public class Toolbar extends ViewGroup {..}

Here's the API definition of ToolBar:

java.lang.Object
   ↳    android.view.View
       ↳    android.view.ViewGroup
           ↳    android.support.v7.widget.Toolbar

Android ViewPager Tutorial and Examples.

ViewPager is a Layout Manager that allows user to swipe through pages either left or right.

In ViewPager each child view is a separate page (a separate tab) in the layout.

ViewPager is one of the most important navigation features of android as it powers most of those swiping you see in apps. Swiping is these days one of the most popular form of navigation and is quite unique when compared to forms of navigation commonly used in desktop and web apps.

Given that our smartphones have become our personal assistants, the ability to swipe is one of those features that have become so common that we forget how it revolutionized how we use our computers(called smartphones).

In majority of cases, ViewPager gets used alongside Fragments and with tabs.

Thus this provides conveniency in terms of suppling and managing the lifecycle of each page. Fragments remember, are subactivities, and activities represent a single screen. Fragments most oftenly get used as pages.

And it is these pages that we can swipe through via ViewPager.Normally you have to provide an implementation of a PagerAdapter to generate the pages that the view shows.

There are two common PagerAdapter subclasses that we use to generate the pages:

  1. FragmentPagerAdapter - An implementation of PagerAdapter that represents each page as a Fragment that is persistently kept in the fragment manager as long as the user can return to the page. Best when navigating between sibling screens representing a fixed, small number of pages.
  2. FragmentStatePagerAdapter- Implementation of PagerAdapter that uses a Fragment to manage each page. This class also handles saving and restoring of fragment's state. Best for paging across a collection of objects for which the number of pages is undetermined. It destroys fragments as the user navigates to other pages, minimizing memory usage.

These are FragmentPagerAdapter and FragmentStatePagerAdapter; each of these classes have simple code showing how to build a full user interface with them.

Best Regards, Oclemy.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think

Dear readers drop us your comments below. We are building a community of students and learners. Start by dropping us your suggestions below. What tutorials do you want us to do for example? Where can we improve? What are some awesome resources out there? Do you have any code you want to share with us?
By the way that example or snippet you have lying in your computer can really help beginner programmers. We can share it here with other students.

Previous Post Next Post