code: public static int getBackgroundColor(Context context, AttributeSet attrs) {
          int color = Color.TRANSPARENT;
  
          if (isHaveAttribute(attrs, "background")) {
              int styleId = attrs.getStyleAttribute();
              int[] attributesArray = new int[]{android.R.attr.background};
  
              try {
                  TypedArray typedArray = context.obtainStyledAttributes(styleId, attributesArray);
                  if (typedArray.length() > 0)
                      color = typedArray.getColor(0, color);
                  typedArray.recycle();
              } catch (Resources.NotFoundException e) {
                  e.printStackTrace();
              }
          }
  
          return color;
      }
docs: Get Background color if the attr is color value
  
  @param context Context
  @param attrs   AttributeSet
  @return Color