final AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar); Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher_round);Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch swatch = palette.getVibrantSwatch(); if(null != swatch) { appBarLayout.setBackgroundColor(swatch.getRgb()); } }
});
出现提示'generateAsync(android.graphics.Bitmap,android.support.v7.graphics.Palette.PaletteAsyncListener)' is deprecated
发现generateAsync方法已经被废弃,用下面方法替换
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch swatch = palette.getVibrantSwatch(); if(null != swatch) { appBarLayout.setBackgroundColor(swatch.getRgb()); } } });
generateAsync is deprecated
最新推荐文章于 2023-07-17 10:02:29 发布