Stay organized with collections
Save and categorize content based on your preferences.
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 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 elevation value.
|
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.
|
int
|
compositeOverlay(int backgroundColor, float elevation)
Blends the calculated elevation overlay color with the provided backgroundColor.
|
int
|
compositeOverlay(int backgroundColor, float elevation, View overlayView)
See compositeOverlay(int, float).
|
int
|
compositeOverlayIfNeeded(int backgroundColor, float elevation, View overlayView)
See compositeOverlayIfNeeded(int, float).
|
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.
|
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.
|
int
|
compositeOverlayWithThemeSurfaceColorIfNeeded(float elevation, View overlayView)
See compositeOverlayWithThemeSurfaceColorIfNeeded(float).
|
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.
|
int
|
getThemeElevationOverlayColor()
Returns the current theme's color int value for R.attr.elevationOverlayColor.
|
int
|
getThemeSurfaceColor()
Returns the current theme's color int value for R.attr.colorSurface.
|
boolean
|
isThemeElevationOverlayEnabled()
Returns the current theme's boolean value for R.attr.elevationOverlayEnabled.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public constructors
ElevationOverlayProvider
public ElevationOverlayProvider (Context context)
| Parameters |
context |
Context |
ElevationOverlayProvider
public ElevationOverlayProvider (boolean elevationOverlayEnabled,
int elevationOverlayColor,
int elevationOverlayAccentColor,
int colorSurface,
float displayDensity)
| Parameters |
elevationOverlayEnabled |
boolean |
elevationOverlayColor |
int |
elevationOverlayAccentColor |
int |
colorSurface |
int |
displayDensity |
float |
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.
| Parameters |
elevation |
float |
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.
| Parameters |
elevation |
float |
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.
| Parameters |
backgroundColor |
int |
elevation |
float |
compositeOverlay
public int compositeOverlay (int backgroundColor,
float elevation,
View overlayView)
See compositeOverlay(int, float).
| Parameters |
backgroundColor |
int |
elevation |
float |
overlayView |
View |
compositeOverlayIfNeeded
public int compositeOverlayIfNeeded (int backgroundColor,
float elevation,
View overlayView)
See compositeOverlayIfNeeded(int, float).
The absolute elevation of the parent of the provided overlayView will also be
factored in when determining the overlay color.
| Parameters |
backgroundColor |
int |
elevation |
float |
overlayView |
View |
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.
| Parameters |
backgroundColor |
int |
elevation |
float |
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.
| Parameters |
elevation |
float |
compositeOverlayWithThemeSurfaceColorIfNeeded
public int compositeOverlayWithThemeSurfaceColorIfNeeded (float elevation,
View overlayView)
See compositeOverlayWithThemeSurfaceColorIfNeeded(float).
The absolute elevation of the parent of the provided overlayView will also be
factored in when determining the overlay color.
| Parameters |
elevation |
float |
overlayView |
View |
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.
| Parameters |
overlayView |
View |
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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[]]