title: Color of GradientDrawable not visible in SwipeToEditCallback in android
body: <p>I am using the swipe to edit/delete feature for the recycler view and want the drawable to be curved so for the SwipeToDeleteCallback.kt I used <strong>GradientDrawable()</strong> as it allows rounded corners</p>
  <pre><code>package com.example.happyplaces.utils
  
  import android.content.Context
  import android.graphics.Canvas
  import android.graphics.Color
  import android.graphics.Paint
  import android.graphics.PorterDuff
  import android.graphics.PorterDuffXfermode
  import android.graphics.drawable.ColorDrawable
  import android.graphics.drawable.GradientDrawable
  import androidx.core.content.ContextCompat
  import androidx.recyclerview.widget.ItemTouchHelper
  import androidx.recyclerview.widget.RecyclerView
  import com.example.happyplaces.R
  
  
  abstract class SwipeToDeleteCallback(context: Context) : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
  
      private val deleteIcon = ContextCompat.getDrawable(context, R.drawable.ic_round_delete_24)
      private val intrinsicWidth = deleteIcon!!.intrinsicWidth
      private val intrinsicHeight = deleteIcon!!.intrinsicHeight
  //    private val background = ColorDrawable()
      private val background = GradientDrawable()
      private val backgroundColor = Color.parseColor(&quot;#f44336&quot;)
      private val clearPaint = Paint().apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR) }
  
  
      override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
          /**
           * To disable &quot;swipe&quot; for specific item return 0 here.
           * For example:
           * if (viewHolder?.itemViewType == YourAdapter.SOME_TYPE) return 0
           * if (viewHolder?.adapterPosition == 0) return 0
           */
          if (viewHolder.adapterPosition == 10) return 0
          return super.getMovementFlags(recyclerView, viewHolder)
      }
  
      override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
          return false
      }
  
      override fun onChildDraw(
          c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder,
          dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean
      ) {
  
          val itemView = viewHolder.itemView
          val itemHeight = itemView.bottom - itemView.top
          val isCanceled = dX == 0f &amp;&amp; !isCurrentlyActive
  
          if (isCanceled) {
              clearCanvas(c, itemView.right + dX, itemView.top.toFloat(), itemView.right.toFloat(), itemView.bottom.toFloat())
              super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
              return
          }
  
          // Draw the red delete background
          background.setColor(backgroundColor)
  //        background.color = backgroundColor
  //        background.setBounds(itemView.right + dX.toInt() - 25, itemView.top + 25, itemView.right - 25, itemView.bottom - 25)
          background.setBounds(itemView.right + dX.toInt() - 100, itemView.top + 27, itemView.right - 27, itemView.bottom - 27)
          background.cornerRadius = 40F
          background.draw(c)
  
          // Calculate position of delete icon
          val deleteIconTop = itemView.top + (itemHeight - intrinsicHeight) / 2
          val deleteIconMargin = (itemHeight - intrinsicHeight) / 2
          val deleteIconLeft = itemView.right - deleteIconMargin - intrinsicWidth
          val deleteIconRight = itemView.right - deleteIconMargin
          val deleteIconBottom = deleteIconTop + intrinsicHeight
  
          // Draw the delete icon
          deleteIcon?.setBounds(deleteIconLeft, deleteIconTop, deleteIconRight, deleteIconBottom)
          deleteIcon?.draw(c)
  
          super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
      }
  
      private fun clearCanvas(c: Canvas?, left: Float, top: Float, right: Float, bottom: Float) {
          c?.drawRect(left, top, right, bottom, clearPaint)
      }
  }
  </code></pre>
  <p>in the above code, I used the background as GradientDrawable()</p>
  <p>and got this result</p>
  <p><a href="https://i.stack.imgur.com/d5YyQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d5YyQ.png" alt="enter image description here" /></a></p>
  <p>But for the <strong>SwipeToEditCallback</strong> it didn't worked, <strong>the color is not showing</strong>,
  Here's the code</p>
  <pre><code>package com.example.happyplaces.utils
  
  import android.content.Context
  import android.graphics.*
  import android.graphics.drawable.ColorDrawable
  import android.graphics.drawable.GradientDrawable
  import androidx.core.content.ContextCompat
  import androidx.recyclerview.widget.ItemTouchHelper
  import androidx.recyclerview.widget.RecyclerView
  import com.example.happyplaces.R
  
  
  abstract class SwipeToEditCallback(context: Context) : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {
  
      private val editIcon = ContextCompat.getDrawable(context, R.drawable.ic_round_edit_24)
      private val intrinsicWidth = editIcon!!.intrinsicWidth
      private val intrinsicHeight = editIcon!!.intrinsicHeight
  //    private val background = ColorDrawable()
      private val background = GradientDrawable()
      private val backgroundColor = Color.parseColor(&quot;#003fff&quot;)
      private val clearPaint = Paint().apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR) }
  
  
      override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
          /**
           * To disable &quot;swipe&quot; for specific item return 0 here.
           * For example:
           * if (viewHolder?.itemViewType == YourAdapter.SOME_TYPE) return 0
           * if (viewHolder?.adapterPosition == 0) return 0
           */
          if (viewHolder.adapterPosition == 10) return 0
          return super.getMovementFlags(recyclerView, viewHolder)
      }
  
      override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
          return false
      }
  
      override fun onChildDraw(
          c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder,
          dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean
      ) {
  
          val itemView = viewHolder.itemView
          val itemHeight = itemView.bottom - itemView.top
          val isCanceled = dX == 0f &amp;&amp; !isCurrentlyActive
  
          if (isCanceled) {
              clearCanvas(c, itemView.left + dX, itemView.top.toFloat(), itemView.left.toFloat(), itemView.bottom.toFloat())
              super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
              return
          }
  
          // Draw the green edit background
  //        background.color = backgroundColor
          background.setColor(backgroundColor)
          background.setBounds(itemView.left + dX.toInt() + 100, itemView.top + 27, itemView.left + 27, itemView.bottom - 27)
          background.cornerRadius = 40F
          background.draw(c)
  
          // Calculate position of edit icon
          val editIconTop = itemView.top + (itemHeight - intrinsicHeight) / 2
          val editIconMargin = (itemHeight - intrinsicHeight)
          val editIconLeft = itemView.left + editIconMargin - intrinsicWidth - 100
          val editIconRight = itemView.left + editIconMargin - 100
          val editIconBottom = editIconTop + intrinsicHeight
  
          // Draw the delete icon
          editIcon!!.setBounds(editIconLeft, editIconTop, editIconRight, editIconBottom)
          editIcon.draw(c)
  
          super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
      }
  
      private fun clearCanvas(c: Canvas?, left: Float, top: Float, right: Float, bottom: Float) {
          c?.drawRect(left, top, right, bottom, clearPaint)
      }
  }
  </code></pre>
  <p>and the screenshot</p>
  <p><a href="https://i.stack.imgur.com/1FxYE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1FxYE.png" alt="enter image description here" /></a></p>