简体   繁体   中英

How to set color of action bar from picture from database?

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=getActionBar(palette.getVibrantColor(getResources().getColor(R.color.colorPrimary)));
                 getWindow().setStatusBarColor(palette.getVibrantColor(getResources().getColor(R.color.primary)));
            }
        });

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?

(palette.getVibrantColor(getResources().getColor(R.color.colorPrimary)))

Should this be inside the brackets

android.app.ActionBar bar=getActionBar(>>HERE?<<); // not outside it?

also, you have used a different color reference at each point...

.getColor(R.color.primary) // this works for the statusbar? check how you put it above...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM