ElevationOverlayProvider
public
class
ElevationOverlayProvider
extends Object
| java.lang.Object | |
| ↳ | com.google.android.material.elevation.ElevationOverlayProvider |
Utility for calculating elevation overlay alpha values and colors.
Summary
Public constructors | |
|---|---|
ElevationOverlayProvider(Context context)
|
|
Public methods | |
|---|---|
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 |
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 |
int
|
getOverlaysColor()
Returns the current theme's color int value for |
int
|
getSurfaceColor()
Returns the current theme's color int value for |
int
|
getSurfaceColorWithOverlayIfNeeded(float elevation)
Returns the current theme's color int value for |
boolean
|
isOverlaysEnabled()
Returns the current theme's boolean value for |
int
|
layerOverlay(int backgroundColor, float elevation)
Calculates a color that represents the layering of the current theme's |
int
|
layerOverlayIfNeeded(int backgroundColor, float elevation)
Applies the calculated elevation overlay (@see #layerOverlay(int, float)) only if the current
theme's |
Inherited methods | |
|---|---|
java.lang.Object
| |
Public constructors
ElevationOverlayProvider
ElevationOverlayProvider (Context context)
| Parameters | |
|---|---|
context |
Context |
Public methods
calculateOverlayAlpha
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.
| Parameters | |
|---|---|
elevation |
float |
| Returns | |
|---|---|
int |
|
calculateOverlayAlphaFraction
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.
| Parameters | |
|---|---|
elevation |
float |
| Returns | |
|---|---|
float |
|
getOverlaysColor
int getOverlaysColor ()
Returns the current theme's color int value for R.attr.elevationOverlaysColor.
| Returns | |
|---|---|
int |
|
getSurfaceColor
int getSurfaceColor ()
Returns the current theme's color int value for R.attr.colorSurface.
| Returns | |
|---|---|
int |
|
getSurfaceColorWithOverlayIfNeeded
int getSurfaceColorWithOverlayIfNeeded (float elevation)
Returns the current theme's color int value for R.attr.colorSurface, with an elevation
overlay applied if needed (@see #layerOverlayIfNeeded(int, float)).
| Parameters | |
|---|---|
elevation |
float |
| Returns | |
|---|---|
int |
|
isOverlaysEnabled
boolean isOverlaysEnabled ()
Returns the current theme's boolean value for R.attr.elevationOverlaysEnabled.
| Returns | |
|---|---|
boolean |
|
layerOverlay
int layerOverlay (int backgroundColor,
float elevation)
Calculates a color that represents the layering of the current theme's R.attr.elevationOverlaysColor on top of the backgroundColor.
An alpha level is applied to the R.attr.elevationOverlaysColor by using a formula
that is based on the provided elevation value.
| Parameters | |
|---|---|
backgroundColor |
int |
elevation |
float |
| Returns | |
|---|---|
int |
|
layerOverlayIfNeeded
int layerOverlayIfNeeded (int backgroundColor,
float elevation)
Applies the calculated elevation overlay (@see #layerOverlay(int, float)) only if the current
theme's R.attr.elevationOverlaysEnabled is true and the backgroundColor matches
the theme's surface color (R.attr.colorSurface); otherwise returns the backgroundColor.
| Parameters | |
|---|---|
backgroundColor |
int |
elevation |
float |
| Returns | |
|---|---|
int |
|
Classes

