سوال: چطوری تو زامارین AlertDialog نمایش بدیم ؟ پاسخ: اگر قصد داشته باشیم تو زامارین AlertDialog نمایش بدیم ، و همچنین ، این کار رو داخل یک Activity انجامش بدیم . باید کدمون رو به صورت زیر بنویسیم👇 کد صفحه Main.axml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:text="Show AlertDialog" android:layout_width="250dp" android:layout_height="wrap_content" android:id="@+id/btnAlertDialog" android:layout_gravity="center" android:layout_margin="10dp" /> <TextView android:text="www.WiaDevelopers.com" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/txtWiaDevelopers" android:gravity="center" android:layout_margin="10dp" /> </LinearLayout> |
کد صفحه MainActivity.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using Android.App; using Android.Widget; using Android.OS; namespace AlertDialog_App { [Activity(Label = "AlertDialog_App", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { Button btnShowAlertDialog; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView (Resource.Layout.Main); //////FindViewById////// btnShowAlertDialog = FindViewById<Button>(Resource.Id.btnAlertDialog); //////FindViewById////// //////Events////// btnShowAlertDialog.Click += BtnShowAlertDialog_Click; //////Events////// } private void BtnShowAlertDialog_Click(object sender, System.EventArgs e) { AlertDialog.Builder alertDiag = new AlertDialog.Builder(this); alertDiag.SetTitle("عنوان AlertDialog"); alertDiag.SetMessage("متن پیام AlertDialog"); alertDiag.SetPositiveButton("Delete", (senderAlert, args) => { Toast.MakeText(this, "Deleted", ToastLength.Short).Show(); }); alertDiag.SetNegativeButton("Cancel", (senderAlert, args) => { alertDiag.Dispose(); }); Dialog diag = alertDiag.Create(); diag.Show(); } } } |
خب دیگه تموم شد ☺️ امیدوارم که آموزش “چطوری تو زامارین AlertDialog نمایش بدیم” براتون مفید واقع شده باشه . و نهایت استفاده رو… ادامه مطلب