0

This is what happened when I Used

I want to get compliment text color from palette object

I tried this, but it didn't work out as supposed to be palette.getVibrantSwatch().getTitleTextColor();

Please help me in showing right Way of Obtaining text color Using Palette

enter image description here

1 Answers1

0

It takes some time to generate colors from supplied resource, that is why you should use Pallet asynchronously.

Bitmap bm = BitmapFactory.decodeResource(getResources(), VersionData.getOsDrawable(osVersion));

    Palette.PaletteAsyncListener listener = new Palette.PaletteAsyncListener() {
        public void onGenerated(Palette palette) {
            Log.d("Palette", "Palette has been generated");
            TextView tv1 = (TextView) findViewById(R.id.tv1);
            TextView tv2 = (TextView) findViewById(R.id.tv2);

// use initialized Pallet here                  tv1.setBackgroundColor(palette.getVibrantColor(0x000000));

tv2.setBackgroundColor(palette.getVibrantColor(0x000000));

            //Noticed the Expanded white doesn't show everywhere, use Palette to fix this
            collapsingToolbar.setExpandedTitleColor(palette.getVibrantColor(0x000000));
        }
    };

    // Start this Async, because it takes some time to generate
    Palette.from(bm).generate(listener);

There is a excellent Material Design sample project https://github.com/mwolfson/android-historian

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11