Exemplo n.º 1
0
        private void Control_Click(object sender, EventArgs e)
        {
            Picker             model  = Element;
            CustomNumberPicker picker = new CustomNumberPicker(Context);

            picker.TextColor     = (Element as BetterPicker).PopupTextColor.ToAndroid();
            picker.ValueChanged += SelectionChanged;
            if (model.Items != null && model.Items.Any())
            {
                picker.MaxValue = model.Items.Count - 1;
                picker.MinValue = 0;
                picker.SetBackgroundColor((Element as BetterPicker).PopupBackground.ToAndroid());
                picker.SetDisplayedValues(model.Items.ToArray());
                picker.TextColor = (Element as BetterPicker).PopupTextColor.ToAndroid();
                SetPickerDividerColor(picker, (Element as BetterPicker).PopupTextColor.ToAndroid());
                picker.WrapSelectorWheel = false;
                picker.Value             = model.SelectedIndex;
            }
            LinearLayout layout = new LinearLayout(Context)
            {
                Orientation = Orientation.Vertical
            };

            layout.SetBackgroundColor((Element as BetterPicker).PopupBackground.ToAndroid());
            layout.AddView(picker);
            ElementController.SetValueFromRenderer(VisualElement.IsFocusedProperty, true);
            AlertDialog.Builder builder = new AlertDialog.Builder(Context);
            builder.SetView(layout);
            builder.SetTitle(model.Title ?? "");
            _dialog = builder.Create();
            Android.Widget.Button Button = _dialog.GetButton((int)DialogButtonType.Positive);
            if (Button != null)
            {
                Button.SetTextColor((Element as BetterPicker).PopupTextColor.ToAndroid());
            }
            Button = _dialog.GetButton((int)DialogButtonType.Negative);
            if (Button != null)
            {
                Button.SetTextColor((Element as BetterPicker).PopupTextColor.ToAndroid());
            }
            Button = _dialog.GetButton((int)DialogButtonType.Neutral);
            if (Button != null)
            {
                Button.SetTextColor((Element as BetterPicker).PopupTextColor.ToAndroid());
            }
            _dialog.Window.SetBackgroundDrawable(new ColorDrawable((Element as BetterPicker).PopupBackground.ToAndroid()));
            _dialog.DismissEvent += (ssender, args) =>
            {
                ElementController?.SetValueFromRenderer(VisualElement.IsFocusedProperty, false);
            };
            _dialog.Show();
        }
Exemplo n.º 2
0
 private void SetPickerDividerColor(CustomNumberPicker picker, Android.Graphics.Color color)
 {
     Java.Lang.Reflect.Field[] fields = picker.Class.GetDeclaredFields();
     foreach (Java.Lang.Reflect.Field pf in fields)
     {
         if (pf.Name.Equals("mSelectionDivider"))
         {
             pf.Accessible = true;
             // set the color as transparent
             pf.Set(picker, new ColorDrawable(color));
         }
     }
 }