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:
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 theDialogFragment
instance:public class AlertFragment : AppCompatDialogFragment { public override View OnCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var view = inflater.Inflate( Resource.Layout.DialogLayout, container, false); ...