zoukankan      html  css  js  c++  java
  • android 5.0 -- Palette

     Palette用来从图片资源中获取颜色内容。

    下面是个对颜色值使用的工具类:
    public class PaletteUtils {
        public static int getColorWithDefault(Palette palette, int defaultColor) {
            Palette.Swatch currentItem = null;
    
            if (currentItem == null) {
           //充满活力的颜色 currentItem
    = palette.getVibrantSwatch(); } if (currentItem == null) {
           //充满活力的暗色调 currentItem
    = palette.getDarkVibrantSwatch();; } if (currentItem == null) {
           //充满活力的亮色调 currentItem
    = palette.getLightVibrantSwatch(); } if (currentItem == null) { //柔和色调
           currentItem
    = palette.getMutedSwatch(); } if (currentItem == null) {
           //柔和暗色调 currentItem
    = palette.getDarkMutedSwatch(); } if (currentItem == null) {
           //柔和亮色调 currentItem
    = palette.getLightMutedSwatch(); } return currentItem != null ? currentItem.getRgb() : defaultColor; } private PaletteUtils() { throw new AssertionError(); } }

    如下是从bitmap里面获取颜色内容,get是获取不同色调的颜色,然后通过getRgb()获取程序所需的真实颜色内容,

    palette.generateAsync是异步的获取bitmap里面颜色的方法,里面的操作是在异步线程中的操作。

    Palette.generate()不是异步的,主线程中操作。

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),  
                SuperAwesomeCardFragment.getBackgroundBitmapPosition(position));  
        // Palette的部分   
        Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {  
            /** 
             * 提取完之后的回调方法 
             */  
            @Override  
            public void onGenerated(Palette palette) {  
                Palette.Swatch vibrant = palette.getVibrantSwatch();  
                /* 界面颜色UI统一性处理,看起来更Material一些 */  
                mPagerSlidingTabStrip.setBackgroundColor(vibrant.getRgb());  
                mPagerSlidingTabStrip.setTextColor(vibrant.getTitleTextColor());  
                // 其中状态栏、游标、底部导航栏的颜色需要加深一下,也可以不加,具体情况在代码之后说明   
                mPagerSlidingTabStrip.setIndicatorColor(colorBurn(vibrant.getRgb()));  
                mToolbar.setBackgroundColor(vibrant.getRgb());  
                if (android.os.Build.VERSION.SDK_INT >= 21) {  
                    Window window = getWindow();  
                    // 很明显,这两货是新API才有的。   
                    window.setStatusBarColor(colorBurn(vibrant.getRgb()));  
                    window.setNavigationBarColor(colorBurn(vibrant.getRgb()));  
                }  
            }  
        });  
  • 相关阅读:
    K-means聚类算法
    实现计算出用户间的共同好友和二度好友
    Mysql和Hive实现列转行,类似reduceByKey操作
    Flink两阶段提交概述
    一些推荐算法的面试题
    收藏推荐算法-机器学习相关博客文章
    Notepad++将多行数据合并成一行
    布隆过滤器
    二叉树问题
    海量数据常见面试问题
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/4984902.html
Copyright © 2011-2022 走看看