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 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; } }