Navigating with the action bar

The action bar is used to allow the user to navigate to a parent activity, as well as show the user where they are in the app.

How to do it...

Navigation with the action bar is an upward navigation, rather than a backward navigation. This navigation is very simple to add and involves only two steps. If we support versions of Android versions below 4.1, we will make use of the support library.

  1. First, we need to ensure that our source activity is accessible using a known name by adding a [Register] attribute:
    [Register("com.xamarincookbook.MainActivity")]
    public class MainActivity : AppCompatActivity
    {
    }
  2. Next, we let the system know which activity we want to navigate up to using a [MetaData] attribute:
    [MetaData( "android.support.PARENT_ACTIVITY", ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.