Search code examples
javaandroidandroid-actionbarpalette

How do I set the color of the action bar using palette library?


I have a bitmap which I use to display an image from firebase in an imageview. I want both the status bar and the action bar's colors to be adjusted by the vibrant color of the pictures from the database. I searched for how to do this, and have the following code below

      Palette.from(myBitmap).generate(new Palette.PaletteAsyncListener() {
        @Override
        public void onGenerated(Palette palette) {

              android.app.ActionBar bar=setBackgrounddrawable(palette.getVibrantColor(getResources().getColor(R.color.colorPrimary)));
             getWindow().setStatusBarColor(palette.getVibrantColor(getResources().getColor(R.colorPrimary)));
        }
    });

But I get an error on the line of code for get action bar saying 'set background drawable cannot be applied to int' When I remove the line of code for setting color of the actionbar only the status bar color is set and not the action bar, how can I set the color of the action bar as well?


Solution

  • As You see, setBackgroundDrawable() receive a param what type is Drawable,

    but you pass an Int Color value in, then you got the error.


    I do not test it, but You can give it a try with:

    setBackgroundDrawable(new ColorDrawable(palette.getVibrantColor(getResources().getColor(R.color.colorPrimary))));