Code example for Drawable

Methods: setCallback

0
        // Retrieve the drawable resource assigned to the android.R.attr.selectableItemBackground 
        // theme attribute from the current theme. 
        TypedArray a = getContext()
                .obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground});
        mForegroundDrawable = a.getDrawable(0);
        mForegroundDrawable.setCallback(this);
        a.recycle();
    } 
 
    @Override 
    protected void drawableStateChanged() { 
        super.drawableStateChanged(); 
 
        // Update the state of the highlight drawable to match 
        // the state of the button. 
        if (mForegroundDrawable.isStateful()) {
            mForegroundDrawable.setState(getDrawableState());
        } 
 
        // Trigger a redraw. 
        invalidate();