2015-04-25 39 views
0

我使用Palette类以编程方式从图像中获取最主要的颜色,然后使用它作为状态栏和工具栏。根据材料设计指南,状态栏颜色应该比工具栏颜色暗两个阴影。如何动态改变颜色的阴影android?

Bitmap bitmap = ((BitmapDrawable) ((ImageView)mImageView).getDrawable()).getBitmap(); 
    if (bitmap != null) { 
     palette = Palette.generate(bitmap); 
     vibrantSwatch = palette.getVibrantSwatch(); 
     darkVibrantSwatch = palette.getDarkVibrantSwatch(); 
    } 

对于较深的颜色,我使用darkVibrantSwatch和较浅的颜色,我使用的是vibrantSwatch。但在大多数情况下,这些结果彼此非常不同,因此基本上变得无法使用。有没有解决方法? 也许如果它可能只有一种颜色,比如说darkVibrantSwatch,然后以编程方式生成两种颜色的颜色较浅?

回答

1

我不确定如何让两个阴影变得更轻,但是您可以使用SHADE_FACTOR来查看是否可以实现您想要的效果。

private int getDarkerShade(int color) { 
     return Color.rgb((int)(SHADE_FACTOR * Color.red(color)), 
       (int)(SHADE_FACTOR * Color.green(color)), 
       (int)(SHADE_FACTOR * Color.blue(color))); 
    } 

代码段从here

0

行之有效是在颜色的HSV表示修改的亮度值的方式采取:

import android.graphics.Color; 
public static int modifyBrightness(int color, float factor) { 
    float[] hsv = new float[3]; 
    Color.colorToHSV(color, hsv); 
    hsv[2] *= factor; 
    return Color.HSVToColor(hsv); 
} 

要获取状态栏适当较深的颜色,使用因子0.8:

int darkerColor = modifyBrightness(color, 0.8);