当前位置: 首页>>代码示例>>Java>>正文


Java ContextCompat.getColor方法代码示例

本文整理汇总了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();
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:21,代码来源:ScanImageviewActivity.java

示例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));
    }
}
 
开发者ID:danimahardhika,项目名称:wallpaperboard,代码行数:17,代码来源:WallpaperBoardSplashActivity.java

示例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();
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:18,代码来源:Button.java

示例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);
    }
}
 
开发者ID:CMPUT301F17T29,项目名称:HabitUp,代码行数:11,代码来源:EditHabitEventActivity.java

示例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();
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:12,代码来源:TagsViewGroup.java

示例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);
            }
        }
    });
}
 
开发者ID:jaysondc,项目名称:TripleTap,代码行数:39,代码来源:SetGameCardView.java

示例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;

}
 
开发者ID:1014277960,项目名称:DailyReader,代码行数:41,代码来源:StatusBarUtil.java

示例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);
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:36,代码来源:VisualizerView.java

示例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));
}
 
开发者ID:IrrilevantHappyLlamas,项目名称:Runnest,代码行数:17,代码来源:RunFragment.java

示例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);
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:9,代码来源:QMUIPullRefreshLayout.java

示例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);
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:29,代码来源:AdapterRule.java

示例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);
    }
}
 
开发者ID:ls1110924,项目名称:ImmerseMode,代码行数:9,代码来源:TlSbNNbwFCwARImmerseMode.java

示例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);
}
 
开发者ID:mainh,项目名称:MainCalendar,代码行数:13,代码来源:ConfirmPopup.java

示例14: getColorId

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public int getColorId(int id){
    return ContextCompat.getColor(getApplicationContext(), id);
}
 
开发者ID:pooi,项目名称:Nearby,代码行数:4,代码来源:EditMyInfoNurseActivity.java

示例15: getColor

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static int getColor(int resId) {
    return ContextCompat.getColor(Utils.getContext(), resId);
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:4,代码来源:ResouceUtil.java


注:本文中的android.support.v4.content.ContextCompat.getColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。