android.content.Context#getColor ( )源码实例Demo

下面列出了android.content.Context#getColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    LayoutInflater.from(context).inflate(R.layout.switch_bar_content, this, true);
    mTextView = findViewById(android.R.id.text1);
    mSwitch = findViewById(android.R.id.checkbox);

    mDisabledBackgroundColor = context.getColor(R.color.material_grey_600);
    mEnabledBackgroundColor = ResourcesUtils.resolveColorAttr(context, android.R.attr.colorAccent);

    mDisabledText = context.getString(R.string.switch_bar_disabled);
    mEnabledText = context.getString(R.string.switch_bar_enabled);

    setOnClickListener(v -> toggle());

    updateViewStates();
}
 
public PreviewActionForegroundDrawable(@NonNull Context context) {
    mBackgroundColor = context.getColor(R.color.material_blue_500);

    mBackgroundPaint = new Paint();
    mBackgroundPaint.setColor(mBackgroundColor);
    mBackgroundPaint.setStyle(Paint.Style.FILL);
    mBackgroundPaint.setAntiAlias(true);

    mIconArcPaint = new Paint();
    mIconArcPaint.setColor(Color.WHITE);
    mIconArcPaint.setStyle(Paint.Style.STROKE);
    mIconArcPaint.setStrokeWidth(context.getResources().getDimension(R.dimen.view_icon_arc_stroke_width));
    mIconArcPaint.setAntiAlias(true);

    mIconDrawable = context.getDrawable(R.drawable.ic_open_in_browser_white_24dp);
    mArrowDrawable = context.getDrawable(R.drawable.ic_keyboard_arrow_up_white_24dp);
    mIconSize = context.getResources().getDimensionPixelSize(R.dimen.view_icon_size);
    mIconMinMargin = context.getResources().getDimensionPixelSize(R.dimen.view_icon_min_margin);
    mIconArcRadiusOffset = context.getResources().getDimensionPixelSize(R.dimen.view_icon_arc_radius_offset);
}
 
源代码3 项目: Badger   文件: TextBadge.java
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
static int badgeTextColor(Context context) {
    Resources.Theme theme = context.getTheme();
    TypedValue typedValue = new TypedValue();
    if (theme.resolveAttribute(R.attr.badgeTextColor, typedValue, true)) {
        return typedValue.data;
    }
    if (theme.resolveAttribute(R.attr.titleTextColor, typedValue, true)) {
        return typedValue.data;
    }
    if (WMATE) {
        return context.getResources().getColor(R.color.badgeTextColor);
    }
    if (theme.resolveAttribute(android.R.attr.titleTextColor, typedValue, true)) {
        return typedValue.data;
    }
    return context.getColor(R.color.badgeTextColor);
}
 
源代码4 项目: Tok-Android   文件: ScreenUtils.java
public static int getColor(@NonNull Context context, @ColorRes int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        return context.getResources().getColor(id);
    }
}
 
源代码5 项目: smartcoins-wallet   文件: SendScreen.java
public static int getColorWrapper(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        return context.getResources().getColor(id);
    }
}
 
源代码6 项目: geopaparazzi   文件: Compat.java
public static int getColor(Context context, int id) {
    int color = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        color = context.getColor(id);
    } else {
        color = context.getResources().getColor(id);
    }
    return color;
}
 
源代码7 项目: AndroidCommons   文件: ResourcesHelper.java
@SuppressWarnings("deprecation")
public static int getColor(@NonNull Context context, @ColorRes int colorResId) {
    if (Build.VERSION.SDK_INT < 23) {
        return context.getResources().getColor(colorResId);
    } else {
        return context.getColor(colorResId);
    }
}
 
源代码8 项目: Musicoco   文件: AlbumPictureController.java
public AlbumPictureController(Context context, final ImageSwitcher view, int size) {
    this.view = view;
    this.size = size;
    this.context = context;
    this.cache = new BitmapCache(context, BitmapCache.CACHE_ALBUM_VISUALIZER_IMAGE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        defaultColor = context.getColor(R.color.default_play_bg_color);
        defaultTextColor = context.getColor(R.color.default_play_text_color);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        defaultColor = context.getResources().getColor(R.color.default_play_bg_color, null);
        defaultTextColor = context.getResources().getColor(R.color.default_play_text_color, null);
    } else {
        defaultColor = context.getResources().getColor(R.color.default_play_bg_color);
        defaultTextColor = context.getResources().getColor(R.color.default_play_text_color);
    }

    this.bitmapProducer = new BitmapProducer(context);

    colors = new int[]{
            defaultColor,
            defaultTextColor,
            defaultColor,
            defaultTextColor
    };

    rotateAnim = ObjectAnimator.ofFloat(0, 360);
    rotateAnim.setDuration(45 * 1000);
    rotateAnim.setRepeatMode(ValueAnimator.RESTART);
    rotateAnim.setRepeatCount(ValueAnimator.INFINITE);
    rotateAnim.setInterpolator(new LinearInterpolator());
    rotateAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            view.getCurrentView().setRotation(value);
        }
    });
}
 
源代码9 项目: Musicoco   文件: ColorUtils.java
/**
 * 0 状态栏背景色<br>
 * 1 标题栏背景色<br>
 * 2 控件首选色<br>
 * 3 主背景色<br>
 * 4 辅背景色<br>
 * 5 主字体色<br>
 * 6 辅字体色<br>
 * 7 底部导航背景色<br>
 * 8 标题栏主字体色<br>
 * 9 标题栏辅字体色<br>
 */
public static int[] get10WhiteThemeColors(Context context) {
    int[] colors = new int[10];
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        colors[0] = context.getColor(R.color.theme_white_primary);
        colors[1] = context.getColor(R.color.theme_white_primary_dark);
        colors[2] = context.getColor(R.color.theme_white_accent);
        colors[3] = context.getColor(R.color.theme_white_main_bg);
        colors[4] = context.getColor(R.color.theme_white_vic_bg);
        colors[5] = context.getColor(R.color.theme_white_main_text);
        colors[6] = context.getColor(R.color.theme_white_vic_text);
        colors[7] = context.getColor(R.color.theme_white_nav);
        colors[8] = context.getColor(R.color.theme_white_toolbar_main_text);
        colors[9] = context.getColor(R.color.theme_white_toolbar_vic_text);
    } else {
        colors[0] = context.getResources().getColor(R.color.theme_white_primary);
        colors[1] = context.getResources().getColor(R.color.theme_white_primary_dark);
        colors[2] = context.getResources().getColor(R.color.theme_white_accent);
        colors[3] = context.getResources().getColor(R.color.theme_white_main_bg);
        colors[4] = context.getResources().getColor(R.color.theme_white_vic_bg);
        colors[5] = context.getResources().getColor(R.color.theme_white_main_text);
        colors[6] = context.getResources().getColor(R.color.theme_white_vic_text);
        colors[7] = context.getResources().getColor(R.color.theme_white_nav);
        colors[8] = context.getResources().getColor(R.color.theme_white_toolbar_main_text);
        colors[9] = context.getResources().getColor(R.color.theme_white_toolbar_vic_text);
    }

    AppPreference preference = new AppPreference(context);
    colors[2] = preference.getAccentColor();

    return colors;
}
 
源代码10 项目: Musicoco   文件: ColorUtils.java
/**
 * 0 主字体颜色
 * 1 辅字体颜色
 */
public static int[] get2WhiteThemeTextColor(Context context) {
    int[] colors = new int[2];

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        colors[0] = context.getColor(R.color.theme_white_main_text); //主字体色
        colors[1] = context.getColor(R.color.theme_white_vic_text); // 辅字体色
    } else {
        colors[0] = context.getResources().getColor(R.color.theme_white_main_text);
        colors[1] = context.getResources().getColor(R.color.theme_white_vic_text);
    }

    return colors;
}
 
源代码11 项目: Musicoco   文件: ColorUtils.java
/**
 * 0 主字体颜色
 * 1 辅字体颜色
 */
public static int[] get2DarkThemeTextColor(Context context) {
    int[] colors = new int[2];

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        colors[0] = context.getColor(R.color.theme_dark_main_text); //主字体色
        colors[1] = context.getColor(R.color.theme_dark_vic_text); // 辅字体色
    } else {
        colors[0] = context.getResources().getColor(R.color.theme_dark_main_text);
        colors[1] = context.getResources().getColor(R.color.theme_dark_vic_text);
    }
    return colors;
}
 
源代码12 项目: Musicoco   文件: ColorUtils.java
public static int[] get2ToolbarTextColors(Context context) {
    int[] colors = new int[2];
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        colors[0] = context.getColor(R.color.white_d);
        colors[1] = context.getColor(R.color.white_d_d);
    } else {
        colors[0] = context.getResources().getColor(R.color.white_d);
        colors[1] = context.getResources().getColor(R.color.white_d_d);
    }

    return colors;
}
 
源代码13 项目: drip-steps   文件: CompatUtils.java
static public int getColor(Context context, int resourceId) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
		return context.getColor(resourceId);
	} else {
		//noinspection deprecation
		return context.getResources().getColor(resourceId);
	}
}
 
源代码14 项目: smartcoins-wallet   文件: AddEditContacts.java
public static int getColorWrapper(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        return context.getResources().getColor(id);
    }
}
 
private int getColor(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        return context.getResources().getColor(id);
    }
}
 
源代码16 项目: talkback   文件: ResourceUtils.java
/** Returns the @colorInt associated with a particular resource ID {@code colorResId}. */
@ColorInt
public static int getColor(@ColorRes int colorResId, Context context) {
  // Resources.getColor(int) is deprecated M onwards and
  // Context.getColor(int) is added from M onwards.
  return context.getColor(colorResId);
}
 
源代码17 项目: FirefoxReality   文件: CustomKeyboardView.java
public CustomKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    LayoutInflater inflate =
            (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int keyTextSize = 0;
    mKeyBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mKeyCapStartBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mVerticalCorrection = 0;
    previewLayout = 0;
    mPreviewOffset = 0;
    mPreviewHeight = 80;
    mKeyTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_text_size);
    mKeyTextColor = 0xFFFFFFFF;
    mLabelTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_longtext_size);
    mPopupLayout = R.layout.keyboard;
    mShadowColor = 0;
    mShadowRadius = 0;
    mBackgroundDimAmount = 0.5f;
    clearHover();

    mPreviewPopup = new PopupWindow(context);
    if (previewLayout != 0) {
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
    } else {
        mShowPreview = false;
    }

    mPreviewPopup.setTouchable(false);

    mPopupKeyboard = new PopupWindow(context);
    mPopupKeyboard.setBackgroundDrawable(null);
    //mPopupKeyboard.setClippingEnabled(false);

    mPopupParent = this;
    //mPredicting = true;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(keyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);
    mPaint.setTypeface(Typeface.create("sans-serif",Typeface.NORMAL));

    mPadding = new Rect(0, 0, 0, 0);
    mMiniKeyboardCache = new HashMap<>();
    mKeyBackground.getPadding(mPadding);
    mKeyboardHoveredPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_hovered_padding);
    mKeyboardPressedPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_pressed_padding);

    mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
    mDisambiguateSwipe = false;

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    resetMultiTap();

    mForegroundColor = context.getColor(R.color.asphalt);
    mSelectedForegroundColor = context.getColor(R.color.fog);
}
 
源代码18 项目: trekarta   文件: DataSourceList.java
DataSourceListAdapter(Context context) {
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mAccentColor = context.getColor(R.color.colorAccentLight);
    mDisabledColor = context.getColor(R.color.colorPrimary);
}
 
源代码19 项目: PasscodeView   文件: Utils.java
@ColorInt
public static int getColorCompat(@NonNull Context context, @ColorRes int colorRes) {
    return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ?
            context.getResources().getColor(colorRes) : context.getColor(colorRes);
}
 
源代码20 项目: NewsMe   文件: ThemeHelper.java
/**
 * Returns a color associated with a particular resource ID
 * <p/>
 * Starting in {@link Build.VERSION_CODES#M}, the returned
 * color will be styled for the specified Context's theme.
 *
 * @param colorId The desired resource identifier, as generated by the aapt
 *                tool. This integer encodes the package, type, and resource
 *                entry. The value 0 is an invalid identifier.
 * @return A single color value in the form 0xAARRGGBB.
 */
public static int getColor(Context context, @ColorRes int colorId) {
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        //noinspection deprecation
        return context.getResources().getColor(colorId);
    } else {
        return context.getColor(colorId);
    }
}
 
 方法所在类
 同类方法