android.graphics.Color类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(251)

本文整理了Java中android.graphics.Color类的一些代码示例,展示了Color类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Color类的具体详情如下:
包路径:android.graphics.Color
类名称:Color

Color介绍

暂无

代码示例

代码示例来源:origin: navasmdc/MaterialDesignLibrary

/**
 * Make a dark color to ripple effect
 * @return
 */
@Override
protected int makePressColor(){
  return Color.parseColor("#88DDDDDD");	
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Sets a color with a specific alpha value.
 *
 * @param color
 * @param alpha from 0-255
 */
public void setColor(int color, int alpha) {
  setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
}

代码示例来源:origin: rey5137/material

public static int getColor(int baseColor, float alphaPercent){				
    int alpha = Math.round(Color.alpha(baseColor) * alphaPercent);
    
    return (baseColor & 0x00FFFFFF) | (alpha << 24);
  }
}

代码示例来源:origin: AppIntro/AppIntro

/**
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
 *              0.0 will return {@code color2}.
 */
private static int blendColors(int color1, int color2, float ratio) {
  final float inverseRation = 1f - ratio;
  float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
  float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
  float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
  return Color.rgb((int) r, (int) g, (int) b);
}

代码示例来源:origin: naman14/Timber

public static int getBlackWhiteColor(int color) {
  double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
  if (darkness >= 0.5) {
    return Color.WHITE;
  } else return Color.BLACK;
}

代码示例来源:origin: navasmdc/MaterialDesignLibrary

/**
 * Make a dark color to ripple effect
 * @return
 */
protected int makePressColor(){
  int r = (this.backgroundColor >> 16) & 0xFF;
  int g = (this.backgroundColor >> 8) & 0xFF;
  int b = (this.backgroundColor >> 0) & 0xFF;
  return Color.argb(128,r, g, b);		
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Returns the Android ICS holo blue light color.
 *
 * @return
 */
public static int getHoloBlue() {
  return Color.rgb(51, 181, 229);
}

代码示例来源:origin: naman14/Timber

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)));
}

代码示例来源:origin: aa112901/remusic

public static int getBlackWhiteColor(int color) {
  double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
  if (darkness >= 0.5) {
    return Color.WHITE;
  } else return Color.BLACK;
}

代码示例来源:origin: navasmdc/MaterialDesignLibrary

/**
   * Make a dark color to ripple effect
   * @return
   */
  protected int makePressColor(){
    int r = (this.backgroundColor >> 16) & 0xFF;
    int g = (this.backgroundColor >> 8) & 0xFF;
    int b = (this.backgroundColor >> 0) & 0xFF;
//        r = (r+90 > 245) ? 245 : r+90;
//        g = (g+90 > 245) ? 245 : g+90;
//        b = (b+90 > 245) ? 245 : b+90;
    return Color.argb(128,r, g, b);		
  }

代码示例来源:origin: navasmdc/MaterialDesignLibrary

/**
 * Make a dark color to ripple effect
 * 
 * @return
 */
protected int makePressColor() {
  int r = (this.backgroundColor >> 16) & 0xFF;
  int g = (this.backgroundColor >> 8) & 0xFF;
  int b = (this.backgroundColor >> 0) & 0xFF;
  r = (r - 30 < 0) ? 0 : r - 30;
  g = (g - 30 < 0) ? 0 : g - 30;
  b = (b - 30 < 0) ? 0 : b - 30;
  return Color.rgb(r, g, b);
}

代码示例来源:origin: AppIntro/AppIntro

/**
 * Set the alpha value of the {@code color} to be the given {@code alpha} value.
 */
private static int setColorAlpha(int color, byte alpha) {
  return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
}

代码示例来源:origin: AppIntro/AppIntro

@Override
  public int getIndicatorColor(int position) {
    return Color.parseColor("#1976D2");
  }
});

代码示例来源:origin: ogaclejapan/SmartTabLayout

/**
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
 * 0.0 will return {@code color2}.
 */
private static int blendColors(int color1, int color2, float ratio) {
 final float inverseRation = 1f - ratio;
 float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
 float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
 float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
 return Color.rgb((int) r, (int) g, (int) b);
}

代码示例来源:origin: bumptech/glide

/**
 * Returns index of palette color closest to c
 *
 */
private int findClosest(int color) {
  if (colorTab == null)
    return -1;
  int r = Color.red(color);
  int g = Color.green(color);
  int b = Color.blue(color);
  int minpos = 0;
  int dmin = 256 * 256 * 256;
  int len = colorTab.length;
  for (int i = 0; i < len;) {
    int dr = r - (colorTab[i++] & 0xff);
    int dg = g - (colorTab[i++] & 0xff);
    int db = b - (colorTab[i] & 0xff);
    int d = dr * dr + dg * dg + db * db;
    int index = i / 3;
    if (usedEntry[index] && (d < dmin)) {
      dmin = d;
      minpos = index;
    }
    i++;
  }
  return minpos;
}

代码示例来源:origin: navasmdc/MaterialDesignLibrary

/**
 * Make a dark color to press effect
 *
 * @return
 */
protected int makePressColor() {
  int r = (this.backgroundColor >> 16) & 0xFF;
  int g = (this.backgroundColor >> 8) & 0xFF;
  int b = (this.backgroundColor >> 0) & 0xFF;
  r = (r - 30 < 0) ? 0 : r - 30;
  g = (g - 30 < 0) ? 0 : g - 30;
  b = (b - 30 < 0) ? 0 : b - 30;
  return Color.argb(70, r, g, b);
}

代码示例来源:origin: navasmdc/MaterialDesignLibrary

/**
 * Make a dark color to ripple effect
 * 
 * @return
 */
protected int makePressColor() {
  int r = (this.backgroundColor >> 16) & 0xFF;
  int g = (this.backgroundColor >> 8) & 0xFF;
  int b = (this.backgroundColor >> 0) & 0xFF;
  r = (r - 30 < 0) ? 0 : r - 30;
  g = (g - 30 < 0) ? 0 : g - 30;
  b = (b - 30 < 0) ? 0 : b - 30;
  return Color.rgb(r, g, b);
}

代码示例来源:origin: rey5137/material

private void resetAnimation(){	
  mStartTime = SystemClock.uptimeMillis();
  mAnimProgress = 0f;
  mCurColorTransparent = Color.alpha(mCurColor) == 0;
  mNextColorTransparent = Color.alpha(mTasks[mCurTask].color) == 0;
  mMaxRadius = getMaxRadius(mTasks[mCurTask].x, mTasks[mCurTask].y, getBounds());
  mShader = null;
}

代码示例来源:origin: nickbutcher/plaid

/**
   * Blend {@code color1} and {@code color2} using the given ratio.
   *
   * @param ratio of which to blend. 0.0 will return {@code color1}, 0.5 will give an even blend,
   *              1.0 will return {@code color2}.
   */
  private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRatio = 1f - ratio;
    float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio);
    float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio);
    float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio);
    float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio);
    return Color.argb((int) a, (int) r, (int) g, (int) b);
  }
}

代码示例来源:origin: AppIntro/AppIntro

@Override
  public int getIndicatorColor(int position) {
    return Color.parseColor("#1976D2");
  }
});

相关文章