/// <summary> /// 添加分割线,由 <see cref="Color"/> 绘制 /// </summary> /// <param name="recycleView"></param> /// <param name="color"></param> /// <param name="size"></param> /// <param name="orientation"></param> public static void AddDividerItemDecoration(this RecyclerView recycleView, int colorArgb, int size = 1, int orientation = DividerItemDecoration.Vertical) { GradientDrawable shape = new(); shape.SetColor(colorArgb); if (orientation == DividerItemDecoration.Vertical) { shape.SetSize(0, size); } else if (orientation == DividerItemDecoration.Horizontal) { shape.SetSize(size, 0); } recycleView.AddDividerItemDecoration(shape, orientation); }
/// <summary> /// 添加分割线,由 <see cref="ColorResAttribute"/> 绘制 /// </summary> /// <param name="recycleView"></param> /// <param name="colorResId"></param> /// <param name="size"></param> /// <param name="orientation"></param> public static void AddDividerItemDecorationRes(this RecyclerView recycleView, [ColorRes] int colorResId, int size = 1, int orientation = DividerItemDecoration.Vertical) { var colorArgb = recycleView.Context !.GetColorCompat(colorResId); recycleView.AddDividerItemDecoration(colorArgb, size, orientation); }
/// <summary> /// 添加分割线,由 <see cref="DrawableResAttribute"/> 绘制 /// </summary> /// <param name="recycleView"></param> /// <param name="drawableResId"></param> /// <param name="orientation"></param> public static void AddDividerItemDecorationRes(this RecyclerView recycleView, [DrawableRes] int drawableResId, int orientation = DividerItemDecoration.Vertical) { var drawable = recycleView.Context !.GetDrawableCompat(drawableResId); recycleView.AddDividerItemDecoration(drawable, orientation); }