Android
Is there a way to change the Text color of the Xamarin Forms Picker for Android? (The spinner that pops up, not the actual control that shows the choice made.)
I've tried this, but the Spinner is always null.
public class CustomPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
CustomPicker element = (CustomPicker)this.Element;
var nativePickerView = (global::Android.Widget.TextView) Control;
element.BackgroundColor = Color.Transparent;
nativePickerView.SetBackgroundColor(element.BackgroundColor.ToAndroid());
nativePickerView.SetCursorVisible(true);
nativePickerView.SetTextColor(Color.Black.ToAndroid());
int spinnerId = nativePickerView.Context.Resources.GetIdentifier("android:id/Spinner", null, null);
var spinnerView = (nativePickerView.FindViewById(spinnerId) as Spinner);
if (spinnerView != null) spinnerView.SetBackgroundColor(Color.Black.ToAndroid());
}
}
The PickerRenderer uses a NumberPicker internally to display the choices in an AlertDialog. I hate to say what so many people have said to me when I want simple customization, but you may be needing a custom renderer. Custom Renderers Guide. Even with a custom renderer, getting at a private field is pretty tough so you may want to "roll-your-own" control for Xamarin.Forms that gives you more control of element appearances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With