color1.setBackgroundColor(palette.getMutedColor(Color.WHITE))
color2.setBackgroundColor(palette.getDarkMutedColor(Color.WHITE))
color3.setBackgroundColor(palette.getLightMutedColor(Color.WHITE))
color4.setBackgroundColor(palette.getVibrantColor(Color.WHITE))
color5.setBackgroundColor(palette.getDarkVibrantColor(Color.WHITE))
color6.setBackgroundColor(palette.getLightVibrantColor(Color.WHITE))
运行后结果如下:

这样各个颜色的差别就一目了然。除了上面的函数,还可以使用`getColorForTarget`这个函数,如下:
@ColorInt
public int getColorForTarget(@NonNull final Target target, @ColorInt final int defaultColor) {
这个函数需要一个Target,提供了6个静态字段,如下:
/**
- A target which has the characteristics of a vibrant color which is light in luminance.
*/
public static final Target LIGHT_VIBRANT;
/**
- A target which has the characteristics of a vibrant color which is neither light or dark.
*/
public static final Target VIBRANT;
/**
- A target which has the characteristics of a vibrant color which is dark in luminance.
*/
public static final Target DARK_VIBRANT;
/**
- A target which has the characteristics of a muted color which is light in luminance.
*/
public static final Target LIGHT_MUTED;
/**
- A target which has the characteristics of a muted color which is neither light or dark.
*/
public static final Target MUTED;
/**
- A target which has the characteristics of a muted color which is dark in luminance.
*/
public static final Target DARK_MUTED;
其实就是对应着上面除了主色调之外的六种颜色。
## 文字颜色自动适配
在上面的运行结果中可以看到,每个颜色上面的文字都很清楚的显示,而且它们并不是同一种颜色。其实这也是Palette提供的功能。
通过下面的函数,我们可以得到各种色调所对应的Swatch对象:
* getDominantSwatch
* getMutedSwatch
* getDarkMutedSwatch
* getLightMutedSwatch
* getVibrantSwatch
* getDarkVibrantSwatch
* getLightVibrantSwatch
注意:同上面一样,也可以通过`getSwatchForTarget(@NonNull final Target target)`来获取
Swatch类提供了以下函数:
* getPopulation(): 样本中的像素数量
* getRgb(): 颜色的RBG值
* getHsl(): 颜色的HSL值
* getBodyTextCo