Code example for StateListDrawable

Methods: addState

0
        if (!mStatesUpdated && v != null) {
            mStatesUpdated = true;
            Bitmap outline = createPressImage(v, mTempCanvas);
            FastBitmapDrawable d = new FastBitmapDrawable(outline);
 
            StateListDrawable states = new StateListDrawable();
            states.addState(new int[] {android.R.attr.state_pressed}, d);
            states.addState(new int[] {android.R.attr.state_focused}, d);
            states.addState(new int[] {}, v.getDrawable());
            v.setImageDrawable(states);
        } 
    } 
 
    /** 
     * Invalidates the pressed/focused states. 
     */ 
    void invalidatePressedFocusedStates(ImageView v) {
        mStatesUpdated = false;
        if (v != null) {
            v.invalidate();
        }