Пример #1
0
        void CreateDialog()
        {
            _listView           = new AListView(_context);
            _listView.Focusable = false;
            _listView.DescendantFocusability = Android.Views.DescendantFocusability.AfterDescendants;
            _listView.SetPadding(
                (int)_context.ToPixels(_PickerCell.Padding.Left),
                (int)_context.ToPixels(_PickerCell.Padding.Top),
                (int)_context.ToPixels(_PickerCell.Padding.Right),
                (int)_context.ToPixels(_PickerCell.Padding.Bottom)
                );
            _listView.SetDrawSelectorOnTop(true);
            _listView.ChoiceMode          = _PickerCell.MaxSelectedNumber == 1 ? Android.Widget.ChoiceMode.Single : Android.Widget.ChoiceMode.Multiple;
            _adapter                      = new PickerAdapter(_context, _PickerCell, _listView);
            _listView.OnItemClickListener = _adapter;
            _listView.Adapter             = _adapter;

            _adapter.CloseAction = () =>
            {
                _dialog.GetButton((int)DialogButtonType.Positive).PerformClick();
            };

            if (_dialog == null)
            {
                using (var builder = new AlertDialog.Builder(_context)) {
                    builder.SetTitle(_PickerCell.PageTitle);
                    builder.SetView(_listView);

                    builder.SetNegativeButton(global::Android.Resource.String.Cancel, (o, args) =>
                    {
                        ClearFocus();
                    });
                    builder.SetPositiveButton(global::Android.Resource.String.Ok, (o, args) =>
                    {
                        _adapter.DoneSelect();
                        UpdateSelectedItems();
                        _PickerCell.InvokeCommand();
                        ClearFocus();
                    });


                    _dialog = builder.Create();
                }



                _dialog.SetCanceledOnTouchOutside(true);
                _dialog.SetOnDismissListener(this);
                _dialog.SetOnShowListener(this);
                _dialog.Show();

                // Pending
                //var buttonTextColor = _PickerCell.AccentColor.IsDefault ? Xamarin.Forms.Color.Accent.ToAndroid() : _PickerCell.AccentColor.ToAndroid();
                //_dialog.GetButton((int)DialogButtonType.Positive).SetTextColor(buttonTextColor);
                //_dialog.GetButton((int)DialogButtonType.Negative).SetTextColor(buttonTextColor);
            }
        }
        private bool ShowActionSheet(Color backgroundcolor, Color fontColor, string title, string[] content, string negativeButton, Action <string> callback)
        {
            bool alercon = false;

            if (ModernAlertsHelper.currentActivity == null)
            {
                throw new Exception("Call ModernAlertHelper.GetInstance().Init(this) in your MainActivity");
            }
            try
            {
                AlertDialog alertdialog = null;
                ModernAlertsHelper.currentActivity.RunOnUiThread(() =>
                {
                    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ModernAlertsHelper.currentActivity);
                    LayoutInflater inflater           = ModernAlertsHelper.currentActivity.LayoutInflater;
                    var convertView = inflater.Inflate(Resource.Layout.customized_alertdialog, null);
                    dialogBuilder.SetView(convertView);
                    LinearLayout bv            = (LinearLayout)convertView.FindViewById(Resource.Id.body_view);
                    LinearLayout listview_root = (LinearLayout)convertView.FindViewById(Resource.Id.listview_root);
                    listview_root.Visibility   = ViewStates.Visible;
                    bv.Visibility = ViewStates.Gone;
                    Android.Widget.ListView lv         = (Android.Widget.ListView)convertView.FindViewById(Resource.Id.listiview);
                    AlertDialogListViewAdapter adapter = new AlertDialogListViewAdapter(ModernAlertsHelper.currentActivity, content, backgroundcolor.ToAndroid(), fontColor.ToAndroid());
                    lv.Adapter = adapter;
                    lv.SetDrawSelectorOnTop(true);
                    lv.Divider       = new ColorDrawable(Color.LightGray.ToAndroid());
                    lv.DividerHeight = 2;
                    var header       = convertView.FindViewById <TextView>(Resource.Id.header);
                    var root         = convertView.FindViewById <LinearLayout>(Resource.Id.root);
                    var lineheader   = convertView.FindViewById(Resource.Id.lineheader);
                    lineheader.SetBackgroundColor(fontColor.ToAndroid());
                    var linebody = convertView.FindViewById(Resource.Id.linebody);
                    linebody.SetBackgroundColor(fontColor.ToAndroid());
                    //var leftSpacer = convertView.FindViewById<LinearLayout>(Resource.Id.leftSpacer);
                    //leftSpacer.Visibility = ViewStates.Visible;
                    var buttons = convertView.FindViewById <LinearLayout>(Resource.Id.buttons);
                    var button1 = convertView.FindViewById <Android.Widget.Button>(Resource.Id.positinvebutton);
                    header.SetTextColor(fontColor.ToAndroid());
                    header.Text = title;
                    buttons.SetBackgroundColor(backgroundcolor.ToAndroid());
                    root.SetBackgroundColor(backgroundcolor.ToAndroid());
                    button1.Visibility = ViewStates.Visible;
                    button1.Text       = negativeButton;
                    button1.SetTextColor(fontColor.ToAndroid());
                    button1.Click += ((si, e) =>
                    {
                        callback(negativeButton);
                        alertdialog.Dismiss();
                    });
                    lv.ItemClick += ((sd, w) =>
                    {
                        callback(content[w.Position]);
                        alertdialog.Dismiss();
                    });
                    lv.ItemSelected += ((sd, w) =>
                    {
                        callback(content[w.Position]);
                        alertdialog.Dismiss();
                    });
                    alertdialog = dialogBuilder.Create();
                    alertdialog.Show();
                    ShowShadow(alertdialog);
                });
            }
            catch (Exception e)
            {
                throw e;
            }
            return(alercon);
        }