Embedded alert fragments

Sometimes, we want more control over how the dialogs are displayed. We may want the dialog to be a popup on a tablet, but to be displayed as a full page on a phone.

Getting ready

If we are going to support Android versions prior to 3.0, we will have to install the Xamarin Support Library v7 AppCompat NuGet or component into our project.

How to do it...

We can use the DialogFragment instance to display either a pop-up dialog or embed it into the activity fragment navigation by using the following steps:

  1. If we want to embed a dialog into the view, we cannot use the alert builder but we have to use normal layouts. Therefore, we inflate a layout in the OnCreateView() method of the DialogFragment instance:
    public class AlertFragment ...

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.