0

Let me make this clear: I create a fragment which is used for playing music. I blur the artwork of album and set it as the background of the fragment. And I need to show the music name and artist name on the fragment. Sometimes the updated artwork background has the pretty close color with text (like both them are black). In this case, I want to change the text color to another contrast color to make the text clear. The ios has the similar function when you set the wall paper.

Does anyone know how to achieve that?

Qiming Chen
  • 35
  • 1
  • 4

2 Answers2

1

Use palette: https://guides.codepath.com/android/Dynamic-Color-using-Palettes

Palette.from(bitmap).maximumColorCount(16).generate(new Palette.PaletteAsyncListener() {
    @Override
    public void onGenerated(Palette palette) {

     // Get the "vibrant" color swatch based on the bitmap
     Palette.Swatch vibrant = palette.getVibrantSwatch();
      if (vibrant != null) {
          // Set the background color of a layout based on the vibrant color
          containerView.setBackgroundColor(vibrant.getRgb());
          // Update the title TextView with the proper text color
          titleView.setTextColor(vibrant.getTitleTextColor());
      }
    }
});

This is an example of using it. Mess around with grabbing different swatches to see what works best.

Lucas Crawford
  • 3,078
  • 2
  • 14
  • 25
0

If u need black or white theme for text please go through Determine font color based on background color

or otherwise use palette for vibrent colours https://guides.codepath.com/android/Dynamic-Color-using-Palettes

Community
  • 1
  • 1
Nivedh
  • 971
  • 1
  • 8
  • 19