如何在XAMARIN中更改Picker的占位符颜色?

4
如何在XAMARIN的Android和iOS中更改选择器占位符的颜色? 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>

不,hichame.yessou,我接受了你的答案。再次感谢 :) - Aslam Ranjha
2个回答

9

对于Xamarin 3.6及以上版本:

使用属性TitleColor

对于Xamarin 3.6及以下版本:

您需要一个自定义渲染器来实现这个功能:

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

        }

    }

}

1
谢谢hichame.yessou,有人知道iOS的同样问题的解决方案吗? - Aslam Ranjha

3
在iOS中,您需要在自定义渲染器中执行类似的操作。
Control.AttributedPlaceholder = 
    new NSAttributedString (Control.AttributedPlaceholder.Value, foregroundColor: UIColor.White);

非常感谢你,Garett。你们通过免费帮助人们提供了如此出色的服务。stackoverflow.com 绝对是一个学习的绝佳场所。 - Aslam Ranjha

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接