title: Android How to duplicate a EditText Drawable Background?
body: <p>I want to change the background color of my edittext when validation fails to a redish color and then, when the user starts to correct it, return the original color.</p>
  
  <p>The EditText has rounded borders, therefore using <em>setBackgroundColor( )</em> does not work here, because it draws an ugly rectangle instead of the nice rounded rectangle.</p>
  
  <p>I tried to save the background and restore it afterwards. And use a new bakground to paint it red. The code below does not work, because <em>tv.getBackground( )</em> returns the same reference to both <strong>originalBg</strong> and <strong>errorBg</strong>. When I set the color filter to <strong>errorBg</strong> I actually change it for <strong>originalBg</strong> too.<br><br></p>
  
  <p>How can I <strong>duplicate</strong> the background object into <strong>errorBg</strong> so I can change the color there?<br><br></p>
  
  <pre class="lang-js prettyprint-override"><code>    final Drawable originalBg = tv.getBackground();
      final Drawable errorBg = tv.getBackground();   &lt;-- this does not create a new Drawable, just the same reference
      errorBg.setColorFilter(0xFFff6347, Mode.MULTIPLY);
      tv.setBackgroundDrawable(errorBg);
      tv.invalidate();
      tv.addTextChangedListener(new TextWatcher() {
  
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
              tv.setBackgroundDrawable(originalBg);
              tv.invalidate();
          }
  
          public void afterTextChanged(Editable s) {}
  
          public void onTextChanged(CharSequence s, int start, int before, int count) {}
  
      });
  </code></pre>