title: Android AlphaAnimation for different states of StatesListDrawable
body: <p>I'm trying to accomplis similar to this fade out effect for my buttons.</p>
  
  <p><a href="http://www.polymer-project.org/components/paper-calculator/demo.html" rel="nofollow">http://www.polymer-project.org/components/paper-calculator/demo.html</a></p>
  
  <p>But I can't really see where to put in my Fade Out animation to accomplish this with my code. </p>
  
  <p>I can not define this with XML as I need the colors to bet programatically from a SQLite Database. </p>
  
  <p>Here's my CustomStatesList:</p>
  
  <pre><code>public class CustomStateList extends StateListDrawable {
  
  private int backgroundColor, highlightColor, selectedColor;
  private int stateFocused = android.R.attr.state_focused;
  private int statePressed = android.R.attr.state_pressed;
  private int stateSelected = android.R.attr.state_selected;
  private ShapeDrawable mCircleShape, mSquareShape;
  private LayerDrawable mLayer;
  
  
  public CustomStateList(Context mContext, int backgroundColor, int highlightColor, int selectedColor) {
      this.backgroundColor = backgroundColor;
      this.highlightColor = highlightColor;
      this.selectedColor = selectedColor;
  
      mCircleShape = new ShapeDrawable();
      mCircleShape.setShape(new OvalShape());
      mCircleShape.getPaint().setColor(highlightColor);
  
      mSquareShape = new ShapeDrawable();
      mSquareShape.setShape(new RectShape());
      mSquareShape.getPaint().setColor(backgroundColor);
  
      Drawable[] layers = new Drawable[] {mSquareShape, mCircleShape};
      mLayer = new LayerDrawable(layers);
  
      this.addState(new int[] {stateFocused }, mLayer);
      this.addState(new int[] {statePressed }, mLayer);
      this.addState(new int[] {stateSelected }, new ColorDrawable(selectedColor));
      this.addState(new int[]{}, mSquareShape);
  }
  
  public int getBackgroundColor() {
      return backgroundColor;
  }
  
  public void setBackgroundColor(int backgroundColor) {
      this.backgroundColor = backgroundColor;
  }
  
  public int getHighlightColor() {
      return highlightColor;
  }
  
  public void setHighlightColor(int highlightColor) {
      this.highlightColor = highlightColor;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>What I want to do is have this animation:</p>
  
  <pre><code>final Animation out = new AlphaAnimation(1.0f, 0.0f);
  </code></pre>
  
  <p>To be applied to the StatesListDrawable whenever is fading out instead of just instant disappearing. But I have no clue where to apply it! Any ideas?</p>
  
  <p>Thanks!!</p>