Xamarin.Android - 防止 AlertDialog 在 PositiveButton 的使用方法
https://www.coder.work/article/399382
var builder = new AlertDialog.Builder(this); View v = LayoutInflater.From(this).Inflate(Resource.Layout.component_alert_checkPackage, null); alert_ed = v.FindViewById<EditText>(Resource.Id.alert_ed_queue_num); alert_tv_info = v.FindViewById<TextView>(Resource.Id.alert_tv_info); builder.SetView(v); builder.SetCancelable(false); builder.SetTitle("温馨提示文本内容"); builder.SetPositiveButton("确定", (EventHandler<DialogClickEventArgs>)null); builder.SetNegativeButton("取消", (EventHandler<DialogClickEventArgs>)null); var dialog = builder.Create(); dialog.Show(); var yesBtn = dialog.GetButton((int)DialogButtonType.Positive); var noBtn = dialog.GetButton((int)DialogButtonType.Negative); yesBtn.Click += async (sender, args) => { await AleDialogRequestAsync(dialog); }; noBtn.Click += (sender, args) => { Finish(); }; alert_ed.EditorAction += async (a, e) => { if (e.Event == null && e.ActionId != ImeAction.Next) { return; } if ((e.Event?.Action == KeyEventActions.Up && e.Event?.KeyCode == Keycode.Enter) || e.ActionId == ImeAction.Next) { await AleDialogRequestAsync(dialog); } };
简单使用
// Build the dialog. var builder = new AlertDialog.Builder(this); builder.SetTitle("Click me!"); // Create empty event handlers, we will override them manually instead of letting the builder handling the clicks. builder.SetPositiveButton("Yes", (EventHandler<DialogClickEventArgs>)null); builder.SetNegativeButton("No", (EventHandler<DialogClickEventArgs>)null); var dialog = builder.Create(); // Show the dialog. This is important to do before accessing the buttons. dialog.Show(); // Get the buttons. var yesBtn = dialog.GetButton((int)DialogButtonType.Positive); var noBtn = dialog.GetButton((int)DialogButtonType.Negative); // Assign our handlers. yesBtn.Click += (sender, args) => { // Don't dismiss dialog. Console.WriteLine("I am here to stay!"); }; noBtn.Click += (sender, args) => { // Dismiss dialog. Console.WriteLine("I will dismiss now!"); dialog.Dismiss(); };
分类:
Xamarin.Android
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
2021-04-06 前端页面实现table可拖动改变列宽