本文整理汇总了Java中android.support.v4.content.ContextCompat.getColor方法的典型用法代码示例。如果您正苦于以下问题:Java ContextCompat.getColor方法的具体用法?Java ContextCompat.getColor怎么用?Java ContextCompat.getColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.content.ContextCompat
的用法示例。
在下文中一共展示了ContextCompat.getColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeBackGroundColor
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private void changeBackGroundColor() {
int colorTo;
int colorFrom;
if (fullScreenMode) {
colorFrom = getResources().getColor(R.color.bg);
colorTo = (ContextCompat.getColor(this, R.color.bg1));
} else {
colorFrom = (ContextCompat.getColor(this, R.color.bg1));
colorTo = getResources().getColor(R.color.bg);
}
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(240);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
ActivityBackground.setBackgroundColor((Integer) animator.getAnimatedValue());
}
});
colorAnimation.start();
}
示例2: initBottomText
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private void initBottomText() {
TextView splashTitle = findViewById(R.id.splash_title);
if (splashTitle != null) {
splashTitle.setText(mConfig.getBottomText());
if (mConfig.getBottomTextColor() != -1) {
splashTitle.setTextColor(mConfig.getBottomTextColor());
} else {
int color = ContextCompat.getColor(this, R.color.splashColor);
splashTitle.setTextColor(ColorHelper.getBodyTextColor(color));
}
splashTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, mConfig.getBottomTextSize());
splashTitle.setTypeface(mConfig.getBottomTextFont(this));
}
}
示例3: Button
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public Button(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Button);
mButtonStyle = typedArray.getInt(R.styleable.Button_r_button_style, DEFAULT);
if (isInEditMode()) {
themeSubColor = Color.BLUE;
themeDarkColor = Color.BLUE;
disableColor = Color.GRAY;
} else {
themeSubColor = typedArray.getInt(R.styleable.Button_r_button_theme_color, SkinHelper.getSkin().getThemeSubColor());
themeDarkColor = typedArray.getInt(R.styleable.Button_r_button_theme_dark_color, SkinHelper.getSkin().getThemeDarkColor());
disableColor = ContextCompat.getColor(getContext(), R.color.base_color_disable);
}
typedArray.recycle();
initButton();
}
示例4: onItemSelected
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int color = ContextCompat.getColor(EditHabitEventActivity.this, R.color.lightgray);
TextView spinnerText = view.findViewById(R.id.spinner_text);
spinnerText.setTextColor(color);
if (action == ViewHabitEventActivity.VIEW_EVENT) {
spinnerText.setPadding(0, 0, 0, 0);
}
}
示例5: init
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private void init(Context context) {
mContext = context;
Resources resources = context.getResources();
mTagWidth = resources.getDimensionPixelSize(R.dimen.tag_width);
mTagsMargin = resources.getDimensionPixelSize(R.dimen.tag_margin);
mTagsTextSize = resources.getDimensionPixelSize(R.dimen.tag_text_size);
mDefaultTagBackgroundColor = ContextCompat.getColor(context, R.color.accent_color_dark);
mTagsToShow = MAX_TAGS;
mIsRtl = QuranSettings.getInstance(context).isArabicNames();
}
示例6: animateFailedSet
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* Change card color. This method wraps the Property Animation API mentioned here
* https://stackoverflow.com/a/14467625/7009268
*/
public void animateFailedSet() {
int colorFrom = ContextCompat.getColor(getContext(), R.color.card_background_normal);
int colorTo = ContextCompat.getColor(getContext(), R.color.fbutton_color_carrot);
final SetGameCardView card = this;
int duration = getContext().getResources().getInteger(R.integer.card_fail_animation_duration_flash);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(duration); // milliseconds
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
card.setCardBackgroundColor((int) animator.getAnimatedValue());
}
});
colorAnimation.setRepeatMode(ValueAnimator.REVERSE);
colorAnimation.setRepeatCount(2);
colorAnimation.start();
colorAnimation.addListener(new AnimatorListenerAdapter()
{
@Override
public void onAnimationEnd(Animator animation)
{
// Once animation is over, animate back to selected or highlighted or normal
card.setChecked(false, false);
if (isHighlighted()) {
animateColorChange(R.color.fbutton_color_alizarin, R.color.card_background_highlighted);
} else {
animateColorChange(R.color.fbutton_color_alizarin, R.color.card_background_normal);
}
}
});
}
示例7: compat
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* 修改状态栏的颜色
* @param activity
* @param statusColor
* @return
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static View compat(Activity activity, int statusColor) {
int color = ContextCompat.getColor(activity, R.color.colorPrimaryDark);
if (statusColor != -1) {
color = statusColor;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().setStatusBarColor(color);
return null;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
//透明状态栏
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 手动添加
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
View statusBarView = new View(activity);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
getStatusBarHeight(activity));
statusBarView.setBackgroundColor(color);
decorView.addView(statusBarView, lp);
((ViewGroup)activity.findViewById(android.R.id.content)).getChildAt(0).setFitsSystemWindows(true);
return statusBarView;
}
return null;
}
示例8: setColor
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* Sets the color of the visualization. This should be one of the preference color values
*
* @param newColorKey
*/
public void setColor(String newColorKey) {
@ColorInt
int shapeColor;
@ColorInt
int trailColor;
if (newColorKey.equals(getContext().getString(R.string.pref_color_blue_value))) {
shapeColor = ContextCompat.getColor(getContext(), R.color.shapeBlue);
trailColor = ContextCompat.getColor(getContext(), R.color.trailBlue);
backgroundColor = ContextCompat.getColor(getContext(), R.color.backgroundBlue);
} else if (newColorKey.equals(getContext().getString(R.string.pref_color_green_value))) {
shapeColor = ContextCompat.getColor(getContext(), R.color.shapeGreen);
trailColor = ContextCompat.getColor(getContext(), R.color.trailGreen);
backgroundColor = ContextCompat.getColor(getContext(), R.color.backgroundGreen);
} else {
shapeColor = ContextCompat.getColor(getContext(), R.color.shapeRed);
trailColor = ContextCompat.getColor(getContext(), R.color.trailRed);
backgroundColor = ContextCompat.getColor(getContext(), R.color.backgroundRed);
}
mBassCircle.setShapeColor(shapeColor);
mMidSquare.setShapeColor(shapeColor);
mTrebleTriangle.setShapeColor(shapeColor);
mBassCircle.setTrailColor(trailColor);
mMidSquare.setTrailColor(trailColor);
mTrebleTriangle.setTrailColor(trailColor);
}
示例9: onMapReady
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* Called when the GoogleMap is ready. Initialize a MapHandler.
*
* @param googleMap The GoogleMap must be non null.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
if (googleMap == null) {
throw new IllegalArgumentException("The GoogleMap must be non null");
}
MapStyleOptions mapStyle = MapStyleOptions.loadRawResourceStyle(getActivity(), R.raw.map_style_no_label);
googleMap.setMapStyle(mapStyle);
mapHandler = new MapHandler(googleMap, ContextCompat.getColor(getContext(), R.color.colorAccent));
}
示例10: setColorSchemeResources
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public void setColorSchemeResources(@ColorRes int... colorResIds) {
final Context context = getContext();
int[] colorRes = new int[colorResIds.length];
for (int i = 0; i < colorResIds.length; i++) {
colorRes[i] = ContextCompat.getColor(context, colorResIds[i]);
}
setColorSchemeColors(colorRes);
}
示例11: AdapterRule
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public AdapterRule(Activity context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.context = context;
this.inflater = LayoutInflater.from(context);
if (prefs.getBoolean("dark_theme", false))
colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY), Color.blue(Color.DKGRAY));
else
colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY), Color.blue(Color.LTGRAY));
TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
try {
colorText = ta.getColor(0, 0);
} finally {
ta.recycle();
}
TypedValue tv = new TypedValue();
context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
colorOn = tv.data;
context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
colorOff = tv.data;
colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed);
iconSize = Util.dips2pixels(48, context);
}
示例12: setNavigationColorRes
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
@Override
public void setNavigationColorRes(@ColorRes int colorRes) {
Activity activity = mActivityRef.get();
if (activity != null) {
int color = ContextCompat.getColor(activity, colorRes);
setNavigationColor(color);
}
}
示例13: ConfirmPopup
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* Instantiates a new Confirm popup.
*
* @param activity the activity
*/
public ConfirmPopup(Activity activity) {
super(activity);
cancelText = activity.getString(android.R.string.cancel);
submitText = activity.getString(android.R.string.ok);
submitTextColor = ThemeStyle.Primary; //ContextCompat.getColor(activity, R.color.okText);
cancelTextColor = ContextCompat.getColor(activity, R.color.cancelText);
}
示例14: getColorId
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public int getColorId(int id){
return ContextCompat.getColor(getApplicationContext(), id);
}
示例15: getColor
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static int getColor(int resId) {
return ContextCompat.getColor(Utils.getContext(), resId);
}