Xamarin.Android allows you to create native Android applications using the same UI controls as you would in Java, except with the flexibility and elegance of a modern language (C#), the power of the .NET Base Class Library (BCL), and two first-class IDEs - Xamarin Studio and Visual Studio - at their fingertips.
For more information on installing Xamarin.Android on your Mac or Windows machine, refer to the Getting Started guides on the Xamarin developer center
Setting the Context
of the dialog
When creating a Dialog
from an Activiy
we can use this
as the context.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
With Fragments
we use the property Context
.
AlertDialog.Builder builder = new AlertDialog.Builder(Context);
Button types
SetNeutralButton()
can be used for a simple notification and confirmation that the notification is read.
SetPositiveButton()
can be used for a confirmation for example: "Are you sure you want to delete this item?"
SetNegativeButton()
is for dismissing the dialog and cancelling it's action.
Disable cancel from backbutton
If we want to make sure that the user can't dismiss the dialog with the back button we can call SetCanceable(false)
. This only works for the back button.
Rotation
If the screen is rotated whilst a dialog is visible it will be dismissed and the ok and cancel actions will not be called. You will need to handle this inside your activity and re-show the dialog after the activity has been reloaded.
To get around this use a DialogFragment
instead.
Requirements
Namespace: Android.App
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Public Constructors
AlertDialog.Builder(Context) :-
Constructor using a context for this builder and the AlertDialog it creates.
AlertDialog.Builder(Context, Int32) :-
Constructor using a context and theme for this builder and the AlertDialog it creates.
Using Material Design AlertDialog
In order to use the modern AlertDialog:
using AlertDialog = Android.Support.V7.App.AlertDialog;
Dear Team,
I think that its good to mention about official Android documentation where toolbar control is explained in details:
https://developer.android.com/reference/android/support/v7/widget/Toolbar.html
There is also interested content about Android.Support.v7 library used in the sample:
Interesting links to broad your knowledge about Android application lifecycle:
https://developer.android.com/reference/android/app/Activity.html
http://www.vogella.com/tutorials/AndroidLifeCycle/article.html
https://github.com/xxv/android-lifecycle
https://developer.android.com/guide/components/fragments.html
https://developer.android.com/guide/components/activities/activity-lifecycle.html