public override void OnChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, bool isCurrentlyActive) { base.OnChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); View itemView = viewHolder.ItemView; int itemHeight = itemView.Height; Boolean isCancelled = dX == 0 && !isCurrentlyActive; if (isCancelled) { clearCanvas(c, itemView.Right + dX, (float)itemView.Top, (float)itemView.Right, (float)itemView.Bottom); base.OnChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); return; } mBackground.SetColorFilter(Color.Red, PorterDuff.Mode.Add); mBackground.SetBounds(itemView.Right + (int)dX, itemView.Top, itemView.Right, itemView.Bottom); mBackground.Draw(c); int deleteIconTop = itemView.Top + (itemHeight - intrinsicHeight) / 2; int deleteIconMargin = (itemHeight - intrinsicHeight) / 2; int deleteIconLeft = itemView.Right - deleteIconMargin - intrinsicWidth; int deleteIconRight = itemView.Right - deleteIconMargin; int deleteIconBottom = deleteIconTop + intrinsicHeight; deleteDrawable.SetBounds(deleteIconLeft, deleteIconTop, deleteIconRight, deleteIconBottom); deleteDrawable.Draw(c); base.OnChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); }
public static bool InsertColorFilterOnTouch(View view, MotionEventActions action) { switch (action) { case MotionEventActions.Down: { var colorDrawable = view.Background as ColorDrawable; if (colorDrawable != null) { var drawable = new ColorDrawable(colorDrawable.Color); drawable.SetColorFilter(new Color(0x77000000), PorterDuff.Mode.SrcAtop); view.Background = drawable; } else { view.Background.SetColorFilter(new Color(0x77000000), PorterDuff.Mode.SrcAtop); } //view.Background = ((Activity)view.Context).Resources.GetDrawable(Resource.Drawable.ic_delete); view.Invalidate(); break; } case MotionEventActions.Up: case MotionEventActions.Cancel: { var colorDrawable = view.Background as ColorDrawable; if (colorDrawable != null) { var drawable = new ColorDrawable(colorDrawable.Color); view.Background = drawable; } else { view.Background.ClearColorFilter(); } view.Invalidate(); break; } } return(false); }