简体   繁体   English

如何更改 XAMARIN 中选择器占位符的颜色?

[英]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?如何在 XAMARIN 中为 ANDROID 和 iOS 更改选择器占位符的颜色? PlaceholderColor = "white" doesn't work. PlaceholderColor = "white" 不起作用。

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

For xamarin 3.6 and above:对于 xamarin 3.6 及更高版本:

Use the property TitleColor .使用属性TitleColor

For Xamarin 3.6 and below:对于 Xamarin 3.6 及更低版本:

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

        }

    }

}

In iOS you would do something similar in your custom renderer.在 iOS 中,您可以在自定义渲染器中执行类似的操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM