Package 

Class DrawableUtils

    • Method Detail

      • setBackgroundCompat

         static void setBackgroundCompat(View view, Drawable drawable)

        Helper method to set the background to a view, depending on the android version.

        Parameters:
        view - the view to apply the drawable
        drawable - drawable object
      • setBackgroundCompat

         static void setBackgroundCompat(View view, @DrawableRes() int drawableRes)

        Helper method to set the background to a view, depending on the android version

        Parameters:
        view - the view to apply the drawable
        drawableRes - drawable resource id
      • setBackgroundCompat

         static void setBackgroundCompat(View view, @ColorRes() int normalColorRes, @ColorRes() int pressedColorRes, @ColorRes() int rippleColorRes)

        Ultra compat method to set the background to a view, providing color resource identifiers.

        Note: If you already have the color in Integer format, please obtain the {@code Drawable} object from getSelectableBackgroundCompat and setit into setBackgroundCompat.

        Parameters:
        view - the view interested at the background
        normalColorRes - the color resource id
        pressedColorRes - the pressed color resource id
        rippleColorRes - the ripple color resource id
      • getDrawableCompat

         static Drawable getDrawableCompat(Context context, @DrawableRes() int drawableRes)

        Helper method to get the drawable by its resource. Specific to the correct android version.

        Parameters:
        context - the context
        drawableRes - drawable resource id
      • getSelectableItemBackground

         static Drawable getSelectableItemBackground(Context context)

        Helper method to get the system (or overridden) default {@code selectableItemBackground} Drawable.Returns the {@code R.attr.selectableItemBackground} of the style attribute.

        Parameters:
        context - the context
      • getColorControlHighlight

        @ColorInt() static int getColorControlHighlight(Context context)

        Helper method to get the system (or overridden) default {@code colorControlHighlight}.Returns the color of the {@code R.attr.colorControlHighlight} of the style attribute.

        Parameters:
        context - the context
      • getSelectableBackgroundCompat

         static Drawable getSelectableBackgroundCompat(@ColorInt() int normalColor, @ColorInt() int pressedColor, @ColorInt() int rippleColor)

        Helper method to get a custom selectable background with Ripple color, if device has at least Lollipop.

        Parameters:
        normalColor - the color in normal state
        pressedColor - the pressed color
        rippleColor - the color of the ripple
      • getRippleDrawable

         static Drawable getRippleDrawable(Drawable drawable, @ColorInt() int rippleColor)

        Adds a ripple effect to any Drawable background.

        Parameters:
        drawable - any background drawable
        rippleColor - the color of the ripple