コード例 #1
0
ファイル: AlertManager.Android.cs プロジェクト: sung-su/maui
            void OnAlertRequested(IView sender, AlertArguments arguments)
            {
                // Verify that the page making the request is part of this activity
                if (!PageIsInThisContext(sender))
                {
                    return;
                }

                int messageID = 16908299;
                var alert     = new DialogBuilder(Activity).Create();

                if (alert == null)
                {
                    return;
                }

                if (alert.Window != null)
                {
                    if (arguments.FlowDirection == FlowDirection.MatchParent && sender is IView view)
                    {
                        alert.Window.DecorView.UpdateFlowDirection(view);
                    }
                    else if (arguments.FlowDirection == FlowDirection.LeftToRight)
                    {
                        alert.Window.DecorView.LayoutDirection = LayoutDirection.Ltr;
                    }
                    else if (arguments.FlowDirection == FlowDirection.RightToLeft)
                    {
                        alert.Window.DecorView.LayoutDirection = LayoutDirection.Rtl;
                    }
                }

                alert.SetTitle(arguments.Title);
                alert.SetMessage(arguments.Message);
                if (arguments.Accept != null)
                {
                    alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true));
                }
                alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false));
                alert.SetCancelEvent((o, args) => { arguments.SetResult(false); });
                alert.Show();

                TextView textView = (TextView)alert.findViewByID(messageID);

                textView.TextDirection = GetTextDirection(sender, arguments.FlowDirection);


                if (alert.GetButton((int)DialogButtonType.Negative).Parent is AView parentView)
                {
                    parentView.LayoutDirection = GetLayoutDirection(sender, arguments.FlowDirection);
                }
            }