# ColorOverlayDimmer

# ColorOverlayDimmer

Artifact:[androidx.leanback:leanback](https://developer.android.com/jetpack/androidx/releases/leanback)  
[View Source](https://cs.android.com/search?q=file:androidx/leanback/graphics/ColorOverlayDimmer.java+class:androidx.leanback.graphics.ColorOverlayDimmer)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/leanback/graphics/ColorOverlayDimmer "View this page in Java")

<br />

```
class ColorOverlayDimmer
```

<br />

*** ** * ** ***

Helper class for assigning a dim color to Paint. It holds the alpha value for the current active level.

## Summary

|                                                        ### Public functions                                                         |
|-------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                         | [applyToColor](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#applyToColor(int))`(color: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Change the RGB of the color according to current dim level.                                                                                                                                                                                                                                                                      |
| `java-static `[ColorOverlayDimmer](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer)`!` | [createColorOverlayDimmer](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#createColorOverlayDimmer(int,float,float))`(` ` dimColor: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` activeLevel: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`,` ` dimmedLevel: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) `)` Creates a ColorOverlayDimmer for the given color and levels.                   |
| `java-static `[ColorOverlayDimmer](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer)`!` | [createDefault](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#createDefault(android.content.Context))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!)` Creates a default ColorOverlayDimmer.                                                                                                                                                                                                                                                               |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                       | [drawColorOverlay](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#drawColorOverlay(android.graphics.Canvas,android.view.View,boolean))`(c: `[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)`!, v: `[View](https://developer.android.com/reference/android/view/View.html)`!, includePadding: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Draw a dim color overlay on top of a child View inside the canvas of the parent View. |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                         | [getAlpha](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#getAlpha())`()` Returns the alpha value for the dimmer.                                                                                                                                                                                                                                                                                                                                                                                         |
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                                     | [getAlphaFloat](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#getAlphaFloat())`()` Returns the float value between 0 and 1 corresponding to alpha between 0 and 255.                                                                                                                                                                                                                                                                                                                                     |
| [Paint](https://developer.android.com/reference/android/graphics/Paint.html)`!`                                                     | [getPaint](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#getPaint())`()` Returns the Paint object set to the current alpha value.                                                                                                                                                                                                                                                                                                                                                                        |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                 | [needsDraw](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#needsDraw())`()` Returns whether the dimmer needs to draw.                                                                                                                                                                                                                                                                                                                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                       | [setActiveLevel](https://developer.android.com/reference/kotlin/androidx/leanback/graphics/ColorOverlayDimmer#setActiveLevel(float))`(level: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Sets the active level of the dimmer.                                                                                                                                                                                                                                                                                   |

## Public functions

### applyToColor

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun applyToColor(color: Int): Int
```

Change the RGB of the color according to current dim level. Maintains the alpha value of the color.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|--------------------------------------|
| `color: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The color to apply the dim level to. |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | A color with the RGB values adjusted by the alpha of the current dim level. |

### createColorOverlayDimmer

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
java-static fun createColorOverlayDimmer(
    dimColor: Int,
    activeLevel: Float,
    dimmedLevel: Float
): ColorOverlayDimmer!
```

Creates a ColorOverlayDimmer for the given color and levels.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| `dimColor: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)        | The color for fully dimmed. Only the RGB values are used; the alpha channel is ignored.               |
| `activeLevel: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | The level of dimming when the View is in its active state. Must be a float value between 0.0 and 1.0. |
| `dimmedLevel: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | The level of dimming when the View is in its dimmed state. Must be a float value between 0.0 and 1.0. |

### createDefault

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
java-static fun createDefault(context: Context!): ColorOverlayDimmer!
```

Creates a default ColorOverlayDimmer.  

### drawColorOverlay

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun drawColorOverlay(c: Canvas!, v: View!, includePadding: Boolean): Unit
```

Draw a dim color overlay on top of a child View inside the canvas of the parent View.  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| `c: `[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)`!`                | Canvas of the parent View.                               |
| `v: `[View](https://developer.android.com/reference/android/view/View.html)`!`                        | A child of the parent View.                              |
| `includePadding: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Set to true to draw overlay on padding area of the View. |

### getAlpha

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun getAlpha(): Int
```

Returns the alpha value for the dimmer.  

### getAlphaFloat

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun getAlphaFloat(): Float
```

Returns the float value between 0 and 1 corresponding to alpha between 0 and 255.  

### getPaint

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun getPaint(): Paint!
```

Returns the Paint object set to the current alpha value.  

### needsDraw

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun needsDraw(): Boolean
```

Returns whether the dimmer needs to draw.  

### setActiveLevel

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun setActiveLevel(level: Float): Unit
```

Sets the active level of the dimmer. Updates the alpha value based on the level.  

|                                        Parameters                                        |
|------------------------------------------------------------------------------------------|-----------------------------------------------------|
| `level: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | A float between 0 (fully dim) and 1 (fully active). |