自動で良い感じの色を抽出してくれるPalette Library がすごい! Android Support Library
Paletteで取得できる色の種類は以下の6つ。
- Vibrant
- Vibrant Dark
- Vibrant Light
- Muted
- Muted Dark
- Muted Light
準備:
build.gradleのdependencies {}の中に以下の記述を書こう。
build.gradleのdependencies {}の中に以下の記述を書こう。
dependencies { compile 'com.android.support:palette-v7:23.0.0'}
あとは以下のPaletteのコードを好きなところに書くだけ。
今回は一番分かりやすいonCreateの中に書きました。
注意!!
今回は一番分かりやすいonCreateの中に書きました。
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher); Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { public void onGenerated(Palette palette) { //Vibrant palette.getVibrantColor(Color.WHITE); //Vibrant Dark palette.getDarkVibrantColor(Color.WHITE); //Vibrant Light palette.getLightVibrantColor(Color.WHITE); //Muted palette.getMutedColor(Color.WHITE); //Muted Dark palette.getDarkMutedColor(Color.WHITE); //Muted Light palette.getLightMutedColor(Color.WHITE); } }); }
注意!!
色々なサイトで.generateAsync()などを使っている例がありますが、現在は非推奨(deprecated)になっているので注意が必要です。
コメント
コメントを投稿