美文网首页
Android调色板---palette

Android调色板---palette

作者: ywzheng | 来源:发表于2016-08-05 11:40 被阅读82次

    Android在v7包中更新的 Palette可以让我们在构造色彩鲜艳的界面时更加方便,通过一个图片的bitmap
    来获取图片当中明暗对比的颜色

    • 1添加palette
      compile 'com.android.support:palette-v7:24.1.1'

    • 2初始化

      • 静态初始化
        Palette palette =
        Palette.from(BitmapFactory.decodeResource(getResources(), R.drawable.demo))
        .generate();
    • 异步方法
      Palette.from(BitmapFactory.decodeResource(getResources(), R.drawable.demo))
      .generate(new Palette.PaletteAsyncListener() {
      @Override
      public void onGenerated(Palette palette) {

                 }
             });
      
    • 3获取 Palette.Swatch
      Palette.Swatch swatch=palette.getVibrantSwatch();//充满活力的样本
      swatch=palette.getLightVibrantSwatch();;//亮
      swatch=palette.getDarkVibrantSwatch();//暗

                     swatch=palette.getMutedSwatch();//柔和的样本
                     swatch=palette.getLightMutedSwatch();//亮
                     swatch=palette.getDarkMutedSwatch();//暗
      
    • 4把颜色值赋给控件
      mTextView.setBackgroundColor(swatch.getRgb());//设置控件背景色
      mTextView.setTextColor(swatch.getBodyTextColor());//设置字体颜色

    相关文章

      网友评论

          本文标题:Android调色板---palette

          本文链接:https://www.haomeiwen.com/subject/piuhsttx.html