Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Latest commit

 

History

History
101 lines (76 loc) · 2.49 KB

COLOR.md

File metadata and controls

101 lines (76 loc) · 2.49 KB

Color

Table of Contents - Color

  1. Gradle Dependency
  2. Color Choosers
    1. Basics
    2. Sub Colors

Gradle Dependency

Color

The color module contains extensions to the core module, such as a color chooser.

dependencies {
  ...
  implementation 'com.afollestad.material-dialogs:color:3.2.1'
}

Color Choosers

Basics

Color choosers show a simple grid of colors.

val colors = intArrayOf(RED, GREEN, BLUE)

MaterialDialog(this).show {
  title(R.string.colors)
  colorChooser(colors) { dialog, color ->
      // Use color integer
  }
  positiveButton(R.string.select)
}

You can specify an initial selection, which is just a color integer:

val colors = intArrayOf(RED, GREEN, BLUE)

MaterialDialog(this).show {
  title(R.string.colors)
  colorChooser(colors, initialSelection = BLUE) { dialog, color ->
      // Use color integer
  }
  positiveButton(R.string.select)
}

Sub Colors

You can specify sub-colors, which are a level down from each top level color. The size of the top level array must match the size of the sub-colors array.

val colors = intArrayOf(RED, GREEN, BLUE) // size = 3

val subColors = listOf( // size = 3
  intArrayOf(LIGHT_RED, RED, DARK_RED, WHITE),
  intArrayOf(LIGHT_GREEN, GREEN, DARK_GREEN, GRAY),
  intArrayOf(LIGHT_BLUE, BLUE, DARK_BLUE, BLACK)
)

MaterialDialog(this).show {
  title(R.string.colors)
  colorChooser(colors, subColors = subColors) { dialog, color ->
      // Use color integer
  }
  positiveButton(R.string.select)
}

ARGB Selection

MaterialDialog(this).show {
  title(R.string.colors)
  colorChooser(
      colors = colors, 
      subColors = subColors,
      allowCustomArgb = true,
      showAlphaSelector = true
  ) { dialog, color ->
      // Use color integer
  }
  positiveButton(R.string.select)
}

Omitting showAlphaSelector will hide the alpha (transparency) selector.