标签:err new ant class 像素 需要 get ble action
在Android 5.0 之后推出的palette,通过这个方法,我们就可以从一张 bitmap 中提取我们需要的颜色,可以使UI风格更加美观融洽。比如,我们可以从图片中提取颜色设置给ActionBar做背景颜色,这样ActionBar的颜色就会随着显示图片的变化而变化。
compile ‘com.android.support:palette-v7:25.1.0’
BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(R.drawable.pic);
Bitmap bitmap = drawable.getBitmap();
Palette.Builder builder = Palette.from(bitmap);
AsyncTask<Bitmap, Void, Palette> generate = builder.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// 有活力的颜色
vibrant = palette.getVibrantSwatch();
// 有活力的暗色
darkVibrant = palette.getDarkVibrantSwatch();
// 有活力的亮色
lightVibrant = palette.getLightVibrantSwatch();
// 柔和的颜色
muted = palette.getMutedSwatch();
// 柔和的暗色
darkMuted = palette.getDarkMutedSwatch();
// 柔和的亮色
lightMuted = palette.getLightMutedSwatch();
// 使用颜色
// 修改Actionbar背景颜色
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(vibrant.getRgb()));
((Button) findViewById(R.id.text)).setTextColor(vibrant.getTitleTextColor());
((Button) findViewById(R.id.text)).setBackgroundColor(vibrant.getRgb());
((Button) findViewById(R.id.text1)).setTextColor(darkVibrant.getTitleTextColor());
((Button) findViewById(R.id.text1)).setBackgroundColor(darkVibrant.getRgb());
((Button) findViewById(R.id.text2)).setTextColor(lightVibrant.getTitleTextColor());
((Button) findViewById(R.id.text2)).setBackgroundColor(lightVibrant.getRgb());
((Button) findViewById(R.id.text3)).setTextColor(muted.getTitleTextColor());
((Button) findViewById(R.id.text3)).setBackgroundColor(muted.getRgb());
((Button) findViewById(R.id.text4)).setTextColor(darkMuted.getTitleTextColor());
((Button) findViewById(R.id.text4)).setBackgroundColor(darkMuted.getRgb());
((Button) findViewById(R.id.text5)).setTextColor(lightMuted.getTitleTextColor());
((Button) findViewById(R.id.text5)).setBackgroundColor(lightMuted.getRgb());
}
});
Android Lollipop 新特性 - Palette;获取图片颜色
标签:err new ant class 像素 需要 get ble action
原文地址:http://blog.csdn.net/qq_23452385/article/details/70185332