我在xamarin.forms应用程序中使用DatePicker控件,该应用程序显示了android设备中日期选择器的底线,但我不希望该行。如何删除该行?
我尝试通过使用一些自定义渲染来删除该行,但是它不起作用。我尝试应用的渲染器是:
public class BorderlessDatePickerRenderer:DatePickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
Control.Background = null;
var layoutParams = new MarginLayoutParams(Control.LayoutParameters);
layoutParams.SetMargins(0, 0, 0, 0);
LayoutParameters = layoutParams;
Control.LayoutParameters = layoutParams;
Control.SetPadding(0, 0, 0, 0);
SetPadding(0, 0, 0, 0);
}
}
}
有人可以帮我吗?
谢谢。
答案 0 :(得分:1)
您可以将背景设置为空,并且应该可以使用:
Control.SetBackgroundResource(0);
更新:
如有查询,请随时还原
[assembly: ExportRenderer(typeof(BorderlessDatePicker), typeof(BorderlessDatePickerRenderer))]
public class BorderlessDatePickerRenderer : DatePickerRenderer
{
public static void Init() { }
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
Control.Background = null;
var layoutParams = new MarginLayoutParams(Control.LayoutParameters);
layoutParams.SetMargins(0, 0, 0, 0);
LayoutParameters = layoutParams;
GradientDrawable gd = new GradientDrawable();
gd.SetStroke(0, Android.Graphics.Color.LightGray);
Control.SetBackgroundDrawable(gd);
Control.LayoutParameters = layoutParams;
Control.SetPadding(0, 0, 0, 0);
SetPadding(0, 0, 0, 0);
}
}
}
答案 1 :(得分:1)
您可以对OnElementChanged使用透明渐变
var gd = new GradientDrawable();
gd.SetStroke(0, Android.Graphics.Color.Transparent);
Control.SetBackground(gd);