android.graphics.Color.rgb()方法的使用及代码示例

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

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

Color.rgb介绍

[英]Return a color-int from red, green, blue components. The alpha component is implicity 255 (fully opaque). These component values should be [0..255], but there is no range check performed, so if they are out of range, the returned color is undefined.
[中]从红色、绿色和蓝色组件返回颜色int。alpha组件是隐式255(完全不透明)。这些组件值应为[0..255],但没有执行范围检查,因此如果它们超出范围,则返回的颜色未定义。

代码示例

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

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

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

/**
 * Converts the given hex-color-string to rgb.
 *
 * @param hex
 * @return
 */
public static int rgb(String hex) {
  int color = (int) Long.parseLong(hex.replace("#", ""), 16);
  int r = (color >> 16) & 0xFF;
  int g = (color >> 8) & 0xFF;
  int b = (color >> 0) & 0xFF;
  return Color.rgb(r, g, b);
}

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

/**
 * Default constructor.
 */
public BaseDataSet() {
  mColors = new ArrayList<Integer>();
  mValueColors = new ArrayList<Integer>();
  // default color
  mColors.add(Color.rgb(140, 234, 255));
  mValueColors.add(Color.BLACK);
}

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

public LineDataSet(List<Entry> yVals, String label) {
  super(yVals, label);
  // mCircleRadius = Utils.convertDpToPixel(4f);
  // mLineWidth = Utils.convertDpToPixel(1f);
  if (mCircleColors == null) {
    mCircleColors = new ArrayList<Integer>();
  }
  mCircleColors.clear();
  // default colors
  // mColors.add(Color.rgb(192, 255, 140));
  // mColors.add(Color.rgb(255, 247, 140));
  mCircleColors.add(Color.rgb(140, 234, 255));
}

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

public RadarChartRenderer(RadarChart chart, ChartAnimator animator,
             ViewPortHandler viewPortHandler) {
  super(animator, viewPortHandler);
  mChart = chart;
  mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mHighlightPaint.setStyle(Paint.Style.STROKE);
  mHighlightPaint.setStrokeWidth(2f);
  mHighlightPaint.setColor(Color.rgb(255, 187, 115));
  mWebPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mWebPaint.setStyle(Paint.Style.STROKE);
  mHighlightCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
}

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

public BarChartRenderer(BarDataProvider chart, ChartAnimator animator,
            ViewPortHandler viewPortHandler) {
  super(animator, viewPortHandler);
  this.mChart = chart;
  mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mHighlightPaint.setStyle(Paint.Style.FILL);
  mHighlightPaint.setColor(Color.rgb(0, 0, 0));
  // set alpha after color
  mHighlightPaint.setAlpha(120);
  mShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mShadowPaint.setStyle(Paint.Style.FILL);
  mBarBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mBarBorderPaint.setStyle(Paint.Style.STROKE);
}

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

public DataRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
  super(viewPortHandler);
  this.mAnimator = animator;
  mRenderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mRenderPaint.setStyle(Style.FILL);
  mDrawPaint = new Paint(Paint.DITHER_FLAG);
  mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mValuePaint.setColor(Color.rgb(63, 63, 63));
  mValuePaint.setTextAlign(Align.CENTER);
  mValuePaint.setTextSize(Utils.convertDpToPixel(9f));
  mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  mHighlightPaint.setStyle(Paint.Style.STROKE);
  mHighlightPaint.setStrokeWidth(2f);
  mHighlightPaint.setColor(Color.rgb(255, 187, 115));
}

代码示例来源: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: PhilJay/MPAndroidChart

public BarDataSet(List<BarEntry> yVals, String label) {
  super(yVals, label);
  mHighLightColor = Color.rgb(0, 0, 0);
  calcStackSize(yVals);
  calcEntryCountIncludingStacks(yVals);
}

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

private LineDataSet createSet() {
  LineDataSet set = new LineDataSet(null, "DataSet 1");
  set.setLineWidth(2.5f);
  set.setCircleRadius(4.5f);
  set.setColor(Color.rgb(240, 99, 99));
  set.setCircleColor(Color.rgb(240, 99, 99));
  set.setHighLightColor(Color.rgb(190, 190, 190));
  set.setAxisDependency(AxisDependency.LEFT);
  set.setValueTextSize(10f);
  return set;
}

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

@Override
public void onValueChanged(int value) {
  color = Color.rgb(red.getValue(), green.getValue(), blue.getValue());
  colorView.setBackgroundColor(color);
}

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

/**
 * generates a random ChartData object with just one DataSet
 *
 * @return Bar data
 */
private BarData generateData(int cnt) {
  ArrayList<BarEntry> entries = new ArrayList<>();
  for (int i = 0; i < 12; i++) {
    entries.add(new BarEntry(i, (float) (Math.random() * 70) + 30));
  }
  BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
  d.setColors(ColorTemplate.VORDIPLOM_COLORS);
  d.setBarShadowColor(Color.rgb(203, 203, 203));
  ArrayList<IBarDataSet> sets = new ArrayList<>();
  sets.add(d);
  BarData cd = new BarData(sets);
  cd.setBarWidth(0.9f);
  return cd;
}

代码示例来源:origin: ksoichiro/Android-ObservableScrollView

/**
 * 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: PhilJay/MPAndroidChart

private LineData generateLineData() {
  LineData d = new LineData();
  ArrayList<Entry> entries = new ArrayList<>();
  for (int index = 0; index < count; index++)
    entries.add(new Entry(index + 0.5f, getRandom(15, 5)));
  LineDataSet set = new LineDataSet(entries, "Line DataSet");
  set.setColor(Color.rgb(240, 238, 70));
  set.setLineWidth(2.5f);
  set.setCircleColor(Color.rgb(240, 238, 70));
  set.setCircleRadius(5f);
  set.setFillColor(Color.rgb(240, 238, 70));
  set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
  set.setDrawValues(true);
  set.setValueTextSize(10f);
  set.setValueTextColor(Color.rgb(240, 238, 70));
  set.setAxisDependency(YAxis.AxisDependency.LEFT);
  d.addDataSet(set);
  return d;
}

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

@Override
protected void init() {
  super.init();
  mAxisLeft = new YAxis(AxisDependency.LEFT);
  mAxisRight = new YAxis(AxisDependency.RIGHT);
  mLeftAxisTransformer = new Transformer(mViewPortHandler);
  mRightAxisTransformer = new Transformer(mViewPortHandler);
  mAxisRendererLeft = new YAxisRenderer(mViewPortHandler, mAxisLeft, mLeftAxisTransformer);
  mAxisRendererRight = new YAxisRenderer(mViewPortHandler, mAxisRight, mRightAxisTransformer);
  mXAxisRenderer = new XAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer);
  setHighlighter(new ChartHighlighter(this));
  mChartTouchListener = new BarLineChartTouchListener(this, mViewPortHandler.getMatrixTouch(), 3f);
  mGridBackgroundPaint = new Paint();
  mGridBackgroundPaint.setStyle(Style.FILL);
  // mGridBackgroundPaint.setColor(Color.WHITE);
  mGridBackgroundPaint.setColor(Color.rgb(240, 240, 240)); // light
  // grey
  mBorderPaint = new Paint();
  mBorderPaint.setStyle(Style.STROKE);
  mBorderPaint.setColor(Color.BLACK);
  mBorderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
}

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

private CandleData generateCandleData() {
  CandleData d = new CandleData();
  ArrayList<CandleEntry> entries = new ArrayList<>();
  for (int index = 0; index < count; index += 2)
    entries.add(new CandleEntry(index + 1f, 90, 70, 85, 75f));
  CandleDataSet set = new CandleDataSet(entries, "Candle DataSet");
  set.setDecreasingColor(Color.rgb(142, 150, 175));
  set.setShadowColor(Color.DKGRAY);
  set.setBarSpace(0.3f);
  set.setValueTextSize(10f);
  set.setDrawValues(false);
  d.addDataSet(set);
  return d;
}

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

@Test
public void testRgb() {
 int color = Color.rgb(160, 160, 160);
 assertThat(color).isEqualTo(-6250336);
}

代码示例来源:origin: google/ExoPlayer

@Test
public void testRgbColorParsingRgbValuesOutOfBounds() {
 int outOfBounds = ColorParser.parseTtmlColor("rgb(999, 999, 999)");
 int color = Color.rgb(999, 999, 999);
 // Behave like the framework does.
 assertThat(outOfBounds).isEqualTo(color);
}

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

private void setData(int count) {
  ArrayList<BarEntry> entries = new ArrayList<>();
  for (int i = 0; i < count; i++) {
    entries.add(data.get(i));
  }
  BarDataSet set;
  if (chart.getData() != null &&
      chart.getData().getDataSetCount() > 0) {
    set = (BarDataSet) chart.getData().getDataSetByIndex(0);
    set.setValues(entries);
    chart.getData().notifyDataChanged();
    chart.notifyDataSetChanged();
  } else {
    set = new BarDataSet(entries, "Sinus Function");
    set.setColor(Color.rgb(240, 120, 124));
  }
  BarData data = new BarData(set);
  data.setValueTextSize(10f);
  data.setValueTypeface(tfLight);
  data.setDrawValues(false);
  data.setBarWidth(0.8f);
  chart.setData(data);
}

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

private LineDataSet createSet() {
  LineDataSet set = new LineDataSet(null, "Dynamic Data");
  set.setAxisDependency(AxisDependency.LEFT);
  set.setColor(ColorTemplate.getHoloBlue());
  set.setCircleColor(Color.WHITE);
  set.setLineWidth(2f);
  set.setCircleRadius(4f);
  set.setFillAlpha(65);
  set.setFillColor(ColorTemplate.getHoloBlue());
  set.setHighLightColor(Color.rgb(244, 117, 117));
  set.setValueTextColor(Color.WHITE);
  set.setValueTextSize(9f);
  set.setDrawValues(false);
  return set;
}

相关文章