Luiz Negrini
Luiz Negrini

Reputation: 666

Picker layout changed when you apply a renderer

Why is Picker's layout being so altered when I apply a custom renderer?

layout after applying Renderer: enter image description here

How to leave the original layout but applying a custom renderer?

And also the confirm button are not showing up anymore. They are white, if you click where they should be they work.

Custom Renderer:

public class MyPickerRenderer : PickerRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            var spinner = new Spinner(this.Context);

            Control.SetBackgroundColor(Color.Transparent.ToAndroid());
            Control.InputType = InputTypes.TextFlagNoSuggestions;
            Control.SetTextColor(Color.Red.ToAndroid());

            spinner.SetBackgroundColor(Color.Red.ToAndroid());
        }
    }
}

Upvotes: 2

Views: 864

Answers (1)

King Chan
King Chan

Reputation: 4302

I had the same problem, and found the solution is this: Make sure you are using Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer not Xamarin.Forms.Platform.Android.PickerRenderer

Answer from here: https://forums.xamarin.com/discussion/100317/custom-renderer-for-picker-automatically-changes-layout-in-app-without-overrides

Upvotes: 2

Related Questions