-
public final class DrawableUtils
-
-
Method Summary
Modifier and Type Method Description static voidsetBackgroundCompat(View view, Drawable drawable)Helper method to set the background to a view, depending on the android version. static voidsetBackgroundCompat(View view, @DrawableRes() int drawableRes)Helper method to set the background to a view, depending on the android version static voidsetBackgroundCompat(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. static DrawablegetDrawableCompat(Context context, @DrawableRes() int drawableRes)Helper method to get the drawable by its resource. static DrawablegetSelectableItemBackground(Context context)Helper method to get the system (or overridden) default {@code selectableItemBackground}Drawable.static intgetColorControlHighlight(Context context)Helper method to get the system (or overridden) default {@code colorControlHighlight}.static DrawablegetSelectableBackgroundCompat(@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. static DrawablegetRippleDrawable(Drawable drawable, @ColorInt() int rippleColor)Adds a ripple effect to any Drawable background. static ColorDrawablegetColorDrawable(@ColorInt() int color)Generates the {@code ColorDrawable}object from the provided Color.-
-
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 drawabledrawable- 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 drawabledrawableRes- 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 backgroundnormalColorRes- the color resource idpressedColorRes- the pressed color resource idrippleColorRes- 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 contextdrawableRes- 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 statepressedColor- the pressed colorrippleColor- 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 drawablerippleColor- the color of the ripple
-
getColorDrawable
static ColorDrawable getColorDrawable(@ColorInt() int color)
Generates the
{@code ColorDrawable}object from the provided Color.- Parameters:
color- the color
-
-
-
-