Android Material Design - How to change background color of Toolbar after CollapsingToolbarLayout is collapsed

前端 未结 6 1789
情歌与酒
情歌与酒 2020-12-07 22:54

After the user scrolls down the screen, the image in the CollapsingToolbarLayout disappears and is left with a toolbar with the back button, content title,

6条回答
  •  抹茶落季
    2020-12-07 23:22

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.header);
    
        Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
            @SuppressWarnings("ResourceType")
    
            @Override
            public void onGenerated(Palette palette) {
                Palette.Swatch vibrant =
                        palette.getVibrantSwatch();
    
                if (vibrant != null) {
    
                    collapsingToolbar.setBackgroundColor(getResources().getColor(R.color.cpb_blue));
                    collapsingToolbar.setStatusBarScrimColor(getResources().getColor(R.color.cpb_blue));
                    collapsingToolbar.setContentScrimColor(getResources().getColor(R.color.cpb_blue));
    
                }
            }
    
        });
    

提交回复
热议问题