Xamarin.Android

Topics related to Xamarin.Android:

Getting started with Xamarin.Android

Bindings

Dialogs

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.

RecyclerView

Toasts

Dialogs


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:

  1. Install Support v7 AppCompat library from the NuGet packages
  2. Replace AlertDialog with Android.Support.V7.App.AlertDialog or add the following statement at the top to make your dialog shine.
        using AlertDialog = Android.Support.V7.App.AlertDialog;

Xamarin.Android - How to create a toolbar

Custom ListView

How to correct the orientation of a picture captured from Android device

App lifecycle - Xamarin.Andorid

Barcode scanning using ZXing library in Xamarin Applications

Publishing your Xamarin.Android APK

Xamarin.Android - Bluetooth communication