android 5.x提供了色调的方法,其实很简单,直接上代码。
api至少21.
/ 创建Palette对象
Palette.generateAsync(bitmap,
new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
// 通过Palette来获取对应的色调
Palette.Swatch vibrant =
palette.getDarkVibrantSwatch();
// 将颜色设置给相应的组件
getActionBar().setBackgroundDrawable(
new ColorDrawable(vibrant.getRgb()));
Window window = getWindow();
window.setStatusBarColor(vibrant.getRgb());
}
});