title: Android: Cloning a drawable in order to make a StateListDrawable with filters
body: <p>I'm trying to make a general framework function that makes any Drawable become highlighted when <strong>pressed/focused/selected/etc</strong>.</p>
  
  <p>My function takes a Drawable and returns a StateListDrawable, where the default state is the Drawable itself, and the state for <code>android.R.attr.state_pressed</code> is the same drawable, just with a filter applied using <code>setColorFilter</code>.</p>
  
  <p>My problem is that I can't clone the drawable and make a separate instance of it with the filter applied. Here is what I'm trying to achieve:</p>
  
  <pre><code>StateListDrawable makeHighlightable(Drawable drawable)
  {
      StateListDrawable res = new StateListDrawable();
  
      Drawable clone = drawable.clone(); // how do I do this??
  
      clone.setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
      res.addState(new int[] {android.R.attr.state_pressed}, clone);
      res.addState(new int[] { }, drawable);
      return res;
  }
  </code></pre>
  
  <p>If I don't clone then the filter is obviously applied to both states. I tried playing with <code>mutate()</code> but it doesn't help..</p>
  
  <p>Any ideas?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The accepted answer indeed clones a drawable. It didn't help me though because my general function fails on a different problem. It seems that when you add a drawable to a StateList, it loses all its filters.</p>