0

我知道默认DatePicker已经有一个底线,但我试图DatePicker在自定义渲染器代码中添加一个底线(出于某种目的)。

我可以设置GradientDrawable对象的完整边框,myGradientDrawable.SetStroke(3, myColor);但我不知道如何只添加底线,所以任何人都可以帮助我吗?

4

1 回答 1

0

尝试这个:

public class CustomPickerRenderer : PickerRenderer
{
    public CustomPickerRenderer(Context context) : base(context)
    {
    }

    private AlertDialog alert;
    private CustomPicker element;
    private int selectedIndex;

    public LayerDrawable AddPickerStyles(string imagePath)
    {
        ColorDrawable borderColorDrawable = new ColorDrawable(Xamarin.Forms.Color.FromHex("#43addf").ToAndroid());
        ColorDrawable backgroundColorDrawable = new ColorDrawable(Xamarin.Forms.Color.FromHex("#7e1b80").ToAndroid());

        Drawable[] drawables = new Drawable[]
        {
            borderColorDrawable, backgroundColorDrawable
        };

        LayerDrawable layerDrawable = new LayerDrawable(drawables);
        layerDrawable.SetLayerInset(1, 0, 0, 0, 5);

        return layerDrawable;
    }

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

        element = (CustomPicker)this.Element;

        if (Control != null && this.Element != null)
        {
            Control.Background = AddPickerStyles(element.Image);
        }
    } 

}
于 2018-12-12T20:16:16.777 回答