0

My app uses GradientDrawable. I have to get colors from GradientDrawable and set it as a background.

private int[] getGradientColors(GradientDrawable drawable) {
    // So I have to add this check, cause getColors() method requires min API 24 or higher
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
       return drawable;
    return Objects.requireNonNull(drawable).getColors();
}

Is there any alternative way to get this colors in API 23?

Hayk Mkrtchyan
  • 2,835
  • 3
  • 19
  • 61

1 Answers1

0

As I understand you want to set gradient as your layout background.

Adding this line to parent layout will set background as gradient

android:background="@drawable/gradient"

OR

Through code

linearLayout.setBackgroundResource(R.drawable.gradient);
Sahil Goyal
  • 415
  • 3
  • 13