Skip to content

Instantly share code, notes, and snippets.

@Rexee
Last active April 25, 2016 15:41
Show Gist options
  • Save Rexee/123f653c27bc367dd679563c921b66ce to your computer and use it in GitHub Desktop.
Save Rexee/123f653c27bc367dd679563c921b66ce to your computer and use it in GitHub Desktop.
Using "Palette"
final int bgColor = getResources().getColor(R.color.colorPrimary);
ImageLoader.getInstance().displayImage(user.getImageUrl(), header, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
Palette.from(loadedImage).generate(new PaletteAsyncListener() {
@SuppressLint("NewApi")
@Override
public void onGenerated(Palette palette) {
Swatch vibrant = palette.getVibrantSwatch();
if (vibrant == null) {
vibrant = palette.getDarkVibrantSwatch();
}
if (vibrant == null) return;
Window window = getWindow();
window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(vibrant.getRgb());
toolbar.setBackgroundColor(palette.getMutedColor(bgColor));
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment