# ElevationOverlayProvider

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/elevation/ElevationOverlayProvider.java)

*** ** * ** ***


```
public class ElevationOverlayProvider
```

<br />

*** ** * ** ***

Utility for calculating elevation overlay alpha values and colors.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#ElevationOverlayProvider(Context)(Context context)` |
| `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#ElevationOverlayProvider(boolean,int,int,int,float)( boolean elevationOverlayEnabled, int elevationOverlayColor, int elevationOverlayAccentColor, int colorSurface, float displayDensity )` |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#calculateOverlayAlpha(float)(float elevation)` Calculates the alpha value, between 0 and 255, that should be used with the elevation overlay color, based on the provided `elevation` value. |
| `float` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#calculateOverlayAlphaFraction(float)(float elevation)` Calculates the alpha fraction, between 0 and 1, that should be used with the elevation overlay color, based on the provided `elevation` value. |
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlay(int,float)(int backgroundColor, float elevation)` Blends the calculated elevation overlay color with the provided `backgroundColor`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlay(int,float,View)(int backgroundColor, float elevation, View overlayView)` See `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlay(int,float)`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlayIfNeeded(int,float)(int backgroundColor, float elevation)` Blends the calculated elevation overlay color (@see #compositeOverlay(int, float)) with the `backgroundColor`, only if the current theme's `R.attr.elevationOverlayEnabled` is true and the `backgroundColor` matches the theme's surface color (` R.attr.colorSurface`); otherwise returns the `backgroundColor`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlayIfNeeded(int,float,View)( int backgroundColor, float elevation, View overlayView )` See `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlayIfNeeded(int,float)`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlayWithThemeSurfaceColorIfNeeded(float)(float elevation)` Blends the calculated elevation overlay color (@see #compositeOverlayIfNeeded(int, float)) with the current theme's color int value for `R.attr.colorSurface` if needed. |
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlayWithThemeSurfaceColorIfNeeded(float,View)( float elevation, View overlayView )` See `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlayWithThemeSurfaceColorIfNeeded(float)`. |
| `float` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#getParentAbsoluteElevation(View)(View overlayView)` Returns the absolute elevation of the parent of the provided `overlayView`, or in other words, the sum of the elevations of all ancestors of the `overlayView`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#getThemeElevationOverlayColor()()` Returns the current theme's color int value for `R.attr.elevationOverlayColor`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#getThemeSurfaceColor()()` Returns the current theme's color int value for `R.attr.colorSurface`. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#isThemeElevationOverlayEnabled()()` Returns the current theme's boolean value for `R.attr.elevationOverlayEnabled`. |

## Public constructors

### ElevationOverlayProvider

```
public ElevationOverlayProvider(Context context)
```

### ElevationOverlayProvider

```
public ElevationOverlayProvider(
    boolean elevationOverlayEnabled,
    int elevationOverlayColor,
    int elevationOverlayAccentColor,
    int colorSurface,
    float displayDensity
)
```

## Public methods

### calculateOverlayAlpha

```
public int calculateOverlayAlpha(float elevation)
```

Calculates the alpha value, between 0 and 255, that should be used with the elevation overlay color, based on the provided `elevation` value.

### calculateOverlayAlphaFraction

```
public float calculateOverlayAlphaFraction(float elevation)
```

Calculates the alpha fraction, between 0 and 1, that should be used with the elevation overlay color, based on the provided `elevation` value.

### compositeOverlay

```
public int compositeOverlay(int backgroundColor, float elevation)
```

Blends the calculated elevation overlay color with the provided `backgroundColor`.

An alpha level is applied to the theme's `R.attr.elevationOverlayColor` by using a formula that is based on the provided `elevation` value.

### compositeOverlay

```
public int compositeOverlay(int backgroundColor, float elevation, View overlayView)
```

See `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlay(int,float)`.

### compositeOverlayIfNeeded

```
public int compositeOverlayIfNeeded(int backgroundColor, float elevation)
```

Blends the calculated elevation overlay color (@see #compositeOverlay(int, float)) with the `backgroundColor`, only if the current theme's `R.attr.elevationOverlayEnabled` is true and the `backgroundColor` matches the theme's surface color (`
R.attr.colorSurface`); otherwise returns the `backgroundColor`.

### compositeOverlayIfNeeded

```
public int compositeOverlayIfNeeded(
    int backgroundColor,
    float elevation,
    View overlayView
)
```

See `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlayIfNeeded(int,float)`.

The absolute elevation of the parent of the provided `overlayView` will also be factored in when determining the overlay color.

### compositeOverlayWithThemeSurfaceColorIfNeeded

```
public int compositeOverlayWithThemeSurfaceColorIfNeeded(float elevation)
```

Blends the calculated elevation overlay color (@see #compositeOverlayIfNeeded(int, float)) with the current theme's color int value for `R.attr.colorSurface` if needed.

### compositeOverlayWithThemeSurfaceColorIfNeeded

```
public int compositeOverlayWithThemeSurfaceColorIfNeeded(
    float elevation,
    View overlayView
)
```

See `https://developer.android.com/reference/com/google/android/material/elevation/ElevationOverlayProvider#compositeOverlayWithThemeSurfaceColorIfNeeded(float)`.

The absolute elevation of the parent of the provided `overlayView` will also be factored in when determining the overlay color.

### getParentAbsoluteElevation

```
public float getParentAbsoluteElevation(View overlayView)
```

Returns the absolute elevation of the parent of the provided `overlayView`, or in other words, the sum of the elevations of all ancestors of the `overlayView`.

### getThemeElevationOverlayColor

```
public int getThemeElevationOverlayColor()
```

Returns the current theme's color int value for `R.attr.elevationOverlayColor`.

### getThemeSurfaceColor

```
public int getThemeSurfaceColor()
```

Returns the current theme's color int value for `R.attr.colorSurface`.

### isThemeElevationOverlayEnabled

```
public boolean isThemeElevationOverlayEnabled()
```

Returns the current theme's boolean value for `R.attr.elevationOverlayEnabled`.