コード例 #1
0
        protected override void Dispose(bool disposing)
        {
            if (!(_nativeControl is null))
            {
                _nativeControl.CheckedChange -= NativeControl_ValueChanged;
            }

            if (!(_nativeRadioButtonControl is null))
            {
                _nativeRadioButtonControl.Dispose();
                _nativeRadioButtonControl = null;
            }

            RemoveElementHandlers();

            try
            {
                base.Dispose(disposing);
                _nativeControl = null;
            }
            catch (Exception)
            {
                return;
            }
        }
コード例 #2
0
        private void ConfigureRadioButton(int index, RadioButton radioButton)
        {
            if (index == Element.SelectedSegment)
            {
                radioButton.SetTextColor(Element.SelectedTextColor.ToAndroid());

                _nativeRadioButtonControl = radioButton;
            }
            else
            {
                var textColor = Element.IsEnabled
                    ? Element.TextColor.ToAndroid()
                    : Element.DisabledColor.ToAndroid();

                radioButton.SetTextColor(textColor);
            }

            radioButton.TextSize = Convert.ToSingle(Element.FontSize);

            var font = Font.OfSize(Element.FontFamily, Element.FontSize).ToTypeface();

            radioButton.SetTypeface(font, TypefaceStyle.Normal);

            var gradientDrawable = (StateListDrawable)radioButton.Background;

            var drawableContainerState = (DrawableContainer.DrawableContainerState)gradientDrawable?.GetConstantState();

            var children = drawableContainerState?.GetChildren();

            if (!(children is null))
            {
                var selectedShape = children[0] is GradientDrawable drawable
                    ? drawable
                    : (GradientDrawable)((InsetDrawable)children[0]).Drawable;

                var unselectedShape = children[1] is GradientDrawable drawable1
                    ? drawable1
                    : (GradientDrawable)((InsetDrawable)children[1]).Drawable;

                var backgroundColor = Element.IsEnabled ? Element.TintColor.ToAndroid() : Element.DisabledColor.ToAndroid();

                var borderColor        = Element.IsEnabled ? Element.BorderColor.ToAndroid() : Element.DisabledColor.ToAndroid();
                var borderWidthInPixel = ConvertDipToPixel(Element.BorderWidth);

                if (!(selectedShape is null))
                {
                    selectedShape.SetStroke(borderWidthInPixel, borderColor);

                    selectedShape.SetColor(backgroundColor);
                }

                if (!(unselectedShape is null))
                {
                    unselectedShape.SetStroke(borderWidthInPixel, borderColor);
                    unselectedShape.SetColor(_unselectedItemBackgroundColor);
                }
            }

            radioButton.Enabled = Element.Children[index].IsEnabled;
        }
        private void Recreate()
        {
            DisposeChildren();
            if (Control == null)
            {
                return;
            }
            Control.RemoveAllViews();
            if (Element == null)
            {
                return;
            }
            if (Element.ItemsSource == null)
            {
                return;
            }

            if (Element.IsVertical)
            {
                Control.Orientation = Orientation.Vertical;
            }

            Func <object, string> getText = x => x.ToString();

            if (Element.LabelPath != null)
            {
                getText = x => (string)x.GetType().GetProperty(Element.LabelPath).GetValue(x);
            }

            if (Element.SelectedItem == null)
            {
                Element.SelectedItem = Element.ItemsSource.Cast <object>().FirstOrDefault();
            }

            foreach (var item in Element.ItemsSource)
            {
                var button = new Android.Widget.RadioButton(this.Context);
                button.Text = getText(item);
                var vh = new ViewHolder <Android.Widget.RadioButton> {
                    Data = item, View = button
                };
                views.Add(vh);
                LinearLayout.LayoutParams lp;
                if (Element.IsVertical)
                {
                    lp = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);
                }
                else
                {
                    lp        = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);
                    lp.Weight = 1;
                }
                button.LayoutParameters = lp;
                Control.AddView(button);
                button.Checked = item == Element.SelectedItem;
                button.Click  += Button_Click;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            int f = 1;

            if (f == 1)
            {
                var control = new Android.Widget.CheckBox(this.Context); control.SetHeight(control.Height + 10);
                (Element as CustomCheckBox).WasCheckedChanged = WasChecked;
                this.SetNativeControl(control);
            }
            else
            {
                var control = new Android.Widget.RadioButton(this.Context); this.SetNativeControl(control);
            }

            base.OnElementChanged(e);
        }
コード例 #5
0
 private void GetControles()
 {
     try
     {
         txtBairro    = FindViewById <Android.Widget.EditText>(Resource.Id.txtBairro);
         txtCEP       = FindViewById <Android.Widget.EditText>(Resource.Id.txtCEP);
         txtCidade    = FindViewById <Android.Widget.EditText>(Resource.Id.txtCidade);
         txtDocumento = FindViewById <Android.Widget.EditText>(Resource.Id.txtDocumento);
         txtEndereco  = FindViewById <Android.Widget.EditText>(Resource.Id.txtEndereco);
         txtNumero    = FindViewById <Android.Widget.EditText>(Resource.Id.txtNumero);
         txtRazao     = FindViewById <Android.Widget.EditText>(Resource.Id.txtRazao);
         txtTelefone  = FindViewById <Android.Widget.EditText>(Resource.Id.txtTelefone);
         spEstado     = FindViewById <Android.Widget.Spinner>(Resource.Id.spEstado);
         rbTPCNPJ     = FindViewById <Android.Widget.RadioButton>(Resource.Id.rbCNPJ);
         rbTPCPF      = FindViewById <Android.Widget.RadioButton>(Resource.Id.rbCPF);
     }
     catch (System.Exception)
     {
         Android.Widget.Toast.MakeText(this, "Erro ao receber controles.", Android.Widget.ToastLength.Short).Show();
     }
 }
コード例 #6
0
        private void NativeControl_ValueChanged(object sender, RadioGroup.CheckedChangeEventArgs e)
        {
            var rg = (RadioGroup)sender;

            if (rg.CheckedRadioButtonId != -1)
            {
                var id          = rg.CheckedRadioButtonId;
                var radioButton = rg.FindViewById(id);
                var radioId     = rg.IndexOfChild(radioButton);
                var v           = (RadioButton)rg.GetChildAt(radioId);
                var color       = Element.IsEnabled ? Element.TextColor.ToAndroid() : Element.DisabledColor.ToAndroid();

                _nativeRadioButtonControl?.SetTextColor(color);

                v.SetTextColor(Element.SelectedTextColor.ToAndroid());

                _nativeRadioButtonControl = v;

                Element.SelectedSegment = radioId;
            }
        }