android.content.res.Resources.getColor()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(255)

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

Resources.getColor介绍

暂无

代码示例

代码示例来源:origin: pockethub/PocketHub

/**
 * Create diff styler
 *
 * @param resources
 */
public DiffStyler(final Resources resources) {
  markerColor = resources.getColor(R.color.diff_marker_text);
  defaultColor = resources.getColor(R.color.text);
}

代码示例来源:origin: square/leakcanary

private static String hexStringColor(Resources resources, @ColorRes int colorResId) {
 return String.format("#%06X", (0xFFFFFF & resources.getColor(colorResId)));
}

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

/**
 * turn an array of resource-colors (contains resource-id integers) into an
 * array list of actual color integers
 *
 * @param r
 * @param colors an integer array of resource id's of colors
 * @return
 */
public static List<Integer> createColors(Resources r, int[] colors) {
  List<Integer> result = new ArrayList<Integer>();
  for (int i : colors) {
    result.add(r.getColor(i));
  }
  return result;
}

代码示例来源:origin: square/leakcanary

SquigglySpan(Resources resources) {
 squigglyPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
 squigglyPaint.setStyle(Paint.Style.STROKE);
 squigglyPaint.setColor(resources.getColor(R.color.leak_canary_leak));
 float strokeWidth =
   resources.getDimensionPixelSize(R.dimen.leak_canary_squiggly_span_stroke_width);
 squigglyPaint.setStrokeWidth(strokeWidth);
 halfStrokeWidth = strokeWidth / 2;
 amplitude = resources.getDimensionPixelSize(R.dimen.leak_canary_squiggly_span_amplitude);
 periodDegrees =
   resources.getDimensionPixelSize(R.dimen.leak_canary_squiggly_span_period_degrees);
 path = new Path();
 float waveHeight = 2 * amplitude + strokeWidth;
 halfWaveHeight = waveHeight / 2;
 referenceColor = resources.getColor(R.color.leak_canary_reference);
}

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

/**
 * Sets the colors that should be used fore this DataSet. Colors are reused
 * as soon as the number of Entries the DataSet represents is higher than
 * the size of the colors array. You can use
 * "new int[] { R.color.red, R.color.green, ... }" to provide colors for
 * this method. Internally, the colors are resolved using
 * getResources().getColor(...)
 *
 * @param colors
 */
public void setColors(int[] colors, Context c) {
  if (mColors == null) {
    mColors = new ArrayList<>();
  }
  mColors.clear();
  for (int color : colors) {
    mColors.add(c.getResources().getColor(color));
  }
}

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

/**
 * ets the colors that should be used for the circles of this DataSet.
 * Colors are reused as soon as the number of Entries the DataSet represents
 * is higher than the size of the colors array. You can use
 * "new String[] { R.color.red, R.color.green, ... }" to provide colors for
 * this method. Internally, the colors are resolved using
 * getResources().getColor(...)
 *
 * @param colors
 */
public void setCircleColors(int[] colors, Context c) {
  List<Integer> clrs = mCircleColors;
  if (clrs == null) {
    clrs = new ArrayList<>();
  }
  clrs.clear();
  for (int color : colors) {
    clrs.add(c.getResources().getColor(color));
  }
  mCircleColors = clrs;
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@SuppressWarnings("deprecation")
public static int getColor(@NonNull Context context, @ColorRes int colorId) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    return context.getColor(colorId);
  }
  return context.getResources().getColor(colorId);
}

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

@TargetApi(23)
private static void configureEditModeLogoV23(Resources resources, ImageView logo) {
 logo.setImageDrawable(resources.getDrawable(R.drawable.exo_edit_mode_logo, null));
 logo.setBackgroundColor(resources.getColor(R.color.exo_edit_mode_background_color, null));
}

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

@SuppressWarnings("deprecation")
private static void configureEditModeLogo(Resources resources, ImageView logo) {
 logo.setImageDrawable(resources.getDrawable(R.drawable.exo_edit_mode_logo));
 logo.setBackgroundColor(resources.getColor(R.color.exo_edit_mode_background_color));
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@SuppressWarnings("deprecation")
public void setColorSchemeColorIds(@IdRes int... resources) {
  final View thisView = this;
  final Resources res = thisView.getResources();
  final int[] colorRes = new int[resources.length];
  for (int i = 0; i < resources.length; i++) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      colorRes[i] = res.getColor(resources[i], getContext().getTheme());
    } else {
      colorRes[i] = res.getColor(resources[i]);
    }
  }
  mProgress.setColorSchemeColors(colorRes);
}
//</editor-fold>

代码示例来源:origin: JessYanCoding/MVPArms

/**
 * 获得颜色
 */
public static int getColor(Context context, int rid) {
  return getResources(context).getColor(rid);
}

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

public Indicator(Context context) {
  super(context);
  setBackgroundColor(getResources().getColor(
      android.R.color.transparent));
}

代码示例来源:origin: florent37/MaterialViewPager

/**
 * Change alpha of the header image dark layer to reveal text.
 */
public void setImageHeaderDarkLayerAlpha() {
  final View headerImageDarkLayerView = findViewById(R.id.materialviewpager_headerImageDarkLayer);
  //if using MaterialViewPagerImageHeader
  if (headerImageDarkLayerView != null) {
    headerImageDarkLayerView.setBackgroundColor(getResources().getColor(android.R.color.black));
    ViewCompat.setAlpha(headerImageDarkLayerView, settings.imageHeaderDarkLayerAlpha);
  }
}

代码示例来源:origin: hdodenhof/CircleImageView

public void setCircleBackgroundColorResource(@ColorRes int circleBackgroundRes) {
  setCircleBackgroundColor(getContext().getResources().getColor(circleBackgroundRes));
}

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

public ButtonIcon(Context context, AttributeSet attrs) {
  super(context, attrs);
  try {
    setBackground(new ColorDrawable(getResources().getColor(R.color.transparent)));
  } catch (NoSuchMethodError e) {
    setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparent)));
  }
  rippleSpeed = Utils.dpToPx(2, getResources());
  rippleSize = Utils.dpToPx(5, getResources());
}

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

public void setBackgroundColor(int color){
  super.setBackgroundColor(getResources().getColor(android.R.color.transparent));
  if(isEnabled())
    beforeBackground = backgroundColor;
  this.backgroundColor = color;
}

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

@Override
  public void run() {
    setChecked(check);
    setPressed(false);
    changeBackgroundColor(getResources().getColor(
        android.R.color.transparent));
  }
});

代码示例来源:origin: JakeWharton/butterknife

@Test public void asInt() {
 IntTarget target = new IntTarget();
 int expected = context.getResources().getColor(R.color.red);
 Unbinder unbinder = new BindColorTest$IntTarget_ViewBinding(target, context);
 assertThat(target.actual).isEqualTo(expected);
 unbinder.unbind();
 assertThat(target.actual).isEqualTo(expected);
}

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

public void setChecked(boolean check) {
  invalidate();
  this.check = check;
  setPressed(false);
  changeBackgroundColor(getResources().getColor(
      android.R.color.transparent));
  if (check) {
    step = 0;
  }
  if (check)
    checkView.changeBackground();
}

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

@Test
@Config
public void themeResolveAttribute_shouldSupportDereferenceResource() {
 TypedValue out = new TypedValue();
 Resources.Theme theme = resources.newTheme();
 theme.applyStyle(R.style.MyBlackTheme, false);
 theme.resolveAttribute(android.R.attr.windowBackground, out, true);
 assertThat(out.type).isNotEqualTo(TypedValue.TYPE_REFERENCE);
 assertThat(out.type).isIn(Range.closed(TypedValue.TYPE_FIRST_COLOR_INT, TypedValue.TYPE_LAST_COLOR_INT));
 int value = resources.getColor(android.R.color.black);
 assertThat(out.data).isEqualTo(value);
}

相关文章

微信公众号

最新文章

更多