public static StateListDrawable getSelectableBackground(Context ctx, @ColorInt int selected_color, boolean animate) {
        StateListDrawable states = new StateListDrawable();

        ColorDrawable clrActive = new ColorDrawable(selected_color);
        states.addState(new int[]{android.R.attr.state_selected}, clrActive);

        states.addState(new int[]{}, ContextCompat.getDrawable(ctx, getSelectableBackground(ctx)));
        
        //if possible we enable animating across states
        if (animate) {
            int duration = ctx.getResources().getInteger(android.R.integer.config_shortAnimTime);
            states.setEnterFadeDuration(duration);
            states.setExitFadeDuration(duration);
        }
        
        return states;
    }
public static StateListDrawable getSelectableBackground ( Context ctx , @ ColorInt int selected_color , boolean animate ) { StateListDrawable states = new StateListDrawable ( ) ; ColorDrawable clrActive = new ColorDrawable ( selected_color ) ; states . addState ( new int [ ] { android . R . attr . state_selected } , clrActive ) ; states . addState ( new int [ ] { } , ContextCompat . getDrawable ( ctx , getSelectableBackground ( ctx ) ) ) ; if ( animate ) { int duration = ctx . getResources ( ) . getInteger ( android . R . integer . config_shortAnimTime ) ; states . setEnterFadeDuration ( duration ) ; states . setExitFadeDuration ( duration ) ; } return states ; }
helper to get the system default selectable background inclusive an active state

@param ctx            the context
@param selected_color the selected color
@param animate        true if you want to fade over the states (only animates if API newer than Build.VERSION_CODES.HONEYCOMB)
@return the StateListDrawable