Xamarin : Alert Dialog
Let's create Xamarin alert dialog with ok and cancel button.
First create the layout
dialog.xaml
x
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "fill_parent"
android:background = "#d3d3d3"
android:layout_height = "fill_parent">
<Button
android:id="@+id/MyButton"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:text = "confirm"
android:textColor = "@android:color/background_dark"
android:background = "@android:color/holo_green_dark" />
</LinearLayout>
Open
DialogActivity.cs
and create it's functionalityx
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate {
AlertDialog.Builder alertDiag = new AlertDialog.Builder(this);
alertDiag.SetTitle("ok or cancel");
alertDiag.SetMessage("want to cancel");
alertDiag.SetPositiveButton("ok", (senderAlert, args) => {
Toast.MakeText(this, "ok", ToastLength.Short).Show();
});
alertDiag.SetNegativeButton("Cancel", (senderAlert, args) => {
alertDiag.Dispose();
});
Dialog diag = alertDiag.Create();
diag.Show();
};
}
Cool.
ReplyDeleteHow can I Read more about it?
ReplyDeleteThe PNP has launched the National Police Clearance Online System (NPCS), offering a comprehensive, fast, and convenient online platform for obtaining police clearances. This system ensures a reliable and efficient process for securing clearances.
ReplyDeletehow to register globe sim
ReplyDeleteText “REG ” to 2882.
Visit a Globe store with your ID.
Register online via Globe’s website or app.
Database is assured that the bearer has a full background check that proves that they are not a criminal or have a negative past.
ReplyDeleteThe provided code snippet offers a clear and effective way to create an alert dialog in Xamarin with OK and Cancel buttons. By following these steps, you can integrate a user-friendly dialog box into your Xamarin app.
ReplyDeleteThe AlertDialog.Builder is used to build the dialog with a title, message, and the two action buttons. The "OK" button triggers a Toast message, while the "Cancel" button dismisses the dialog without further action.
If you need additional resources or guides for improving your app, don't hesitate to visit the site for helpful tools and information.