Show a custom dialog in your Xamarin Android app

Sometimes you want to show your users a dialog that contains more than just text and buttons. In those cases the pre-defined AlertDialog that come with Android will need some adjustment. Read here how to do that.

First of all we need an Alert Dialog Builder as always when it comes to creating dialogs in Android. If you want to go with backwards compatibility you should use the one that can be found inside the Android.Support.V7.App class, but you don’t necessarily need to. Instead of simply adding a title and a message we now have the chance to inflate our custom layout and set it as the dialog’s view.

Once the view is attached to the dialog we can manipulate it. We can access its elements by calling FindViewById from the dialogView.

Of course you can still attach buttons and event hanlders to your dialog or set a title, like you are used to it when working with the pre-definded alert dialog.

Don’t forget to show the dialog with builder.Show() and proudly present your first custom dialog to your users!

2 Comments on “Show a custom dialog in your Xamarin Android app

  1. The buttons work fine but not the Edittext, I cannot set or get their value, I have been trying for almost an entire day.

Leave a Reply