Google has their Color - Guidelines, so how to randomly receive a color? Is there a way to specify a number from the table and receive a random color out of all colors of the table?
For example getMatColor(100);
:
EDIT - Result:
(Icon colors)
Google has their Color - Guidelines, so how to randomly receive a color? Is there a way to specify a number from the table and receive a random color out of all colors of the table?
For example getMatColor(100);
:
EDIT - Result:
(Icon colors)
Better late than never.
My new response if the real purpose is to get a random material color for a type of color.
Add the array.xml file (from @8m47x)
Add the following method to pick a random color from a parent type
Usage
Here is a class I wrote. You can create your own material color palette or get a random color.
Example uses:
MaterialColorPalette.java
Just copy the class into your project and add the package declaration.
As Tibox described:
1. Add the Material Colors to
array.xml
:2. Add
getMDcolor()
to your class:3. Usage:
getMDcolor("<md color id>")
mdcolor_50
mdcolor_100
mdcolor_200
mdcolor_300
mdcolor_400
mdcolor_500
mdcolor_600
mdcolor_700
mdcolor_800
mdcolor_900
mdcolor_A100
mdcolor_A200
mdcolor_A400
mdcolor_A700
extras
Using reflection you can retrieve all java.awt.Color constants, some 148 colors with names
This uses reflection, and assumes that the constant name is a human readable name.
So add the colors in a list, and randomly pick one with
random.nextInt(colors.size())
.If you want something working with older SDK you can try this way :
You need to declare your colors in a arrays.xml :
But be careful it's probably less efficient than reflection.