Aslam Ranjha
Aslam Ranjha

Reputation: 63

How to change the color of placeholder of the Picker in XAMARIN?

How to change the color of placeholder of the Picker in XAMARIN for ANDROID and iOS both? PlaceholderColor = "white" doesn't work.

            <Picker Title="Search items"  TextColor="White"
            PlaceholderColor = "white"
            VerticalOptions="Start">
            <Picker.Items>
                <x:String>Item1</x:String>
                <x:String>item2</x:String>
                <x:String>item3</x:String>
            </Picker.Items>
        </Picker>

Upvotes: 4

Views: 3135

Answers (2)

Hichame Yessou
Hichame Yessou

Reputation: 2708

For xamarin 3.6 and above:

Use the property TitleColor.

For Xamarin 3.6 and below:

You need a custom renderer for that:

[assembly: ExportRenderer(typeof(Picker), typeof(CustomPicker))]
namespace Droid
{
    public class CustomPicker : PickerRenderer
    {

        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
        {
            base.OnElementChanged (e);

            if (Control != null) 
                Control.SetHintTextColor (Android.Graphics.Color.Rgb(1,2,3));

        }

    }

}

Upvotes: 9

Garett
Garett

Reputation: 16828

In iOS you would do something similar in your custom renderer.

Control.AttributedPlaceholder = 
    new NSAttributedString (Control.AttributedPlaceholder.Value, foregroundColor: UIColor.White);

Upvotes: 3

Related Questions