本文整理匯總了Java中android.support.annotation.ColorInt類的典型用法代碼示例。如果您正苦於以下問題:Java ColorInt類的具體用法?Java ColorInt怎麽用?Java ColorInt使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ColorInt類屬於android.support.annotation包,在下文中一共展示了ColorInt類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: styleAccuracy
import android.support.annotation.ColorInt; //導入依賴的package包/類
private void styleAccuracy(float accuracyAlpha, @ColorInt int accuracyColor) {
layerMap.get(ACCURACY_LAYER).setProperties(
circleColor(accuracyColor),
circleOpacity(accuracyAlpha),
circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP),
circleStrokeWidth(0.5f),
circleStrokeColor(accuracyColor)
);
}
示例2: setColor
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* 設置狀態欄顏色
*
* @param activity 需要設置的activity
* @param color 狀態欄顏色值
* @param statusBarAlpha 狀態欄透明度
*/
public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
if (fakeStatusBarView != null) {
if (fakeStatusBarView.getVisibility() == View.GONE) {
fakeStatusBarView.setVisibility(View.VISIBLE);
}
fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
} else {
decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
}
setRootView(activity);
}
}
示例3: createItemSeparatorBg
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* 動態創建帶上分隔線或下分隔線的Drawable
*
* @param separatorColor
* @param bgColor
* @param top
* @return
*/
public static LayerDrawable createItemSeparatorBg(@ColorInt int separatorColor, @ColorInt int bgColor, int separatorHeight, boolean top) {
ShapeDrawable separator = new ShapeDrawable();
separator.getPaint().setStyle(Paint.Style.FILL);
separator.getPaint().setColor(separatorColor);
ShapeDrawable bg = new ShapeDrawable();
bg.getPaint().setStyle(Paint.Style.FILL);
bg.getPaint().setColor(bgColor);
Drawable[] layers = {separator, bg};
LayerDrawable layerDrawable = new LayerDrawable(layers);
layerDrawable.setLayerInset(1, 0, top ? separatorHeight : 0, 0, top ? 0 : separatorHeight);
return layerDrawable;
}
示例4: showSnackbar
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* 設置snackbar文字和背景顏色
*
* @param parent 父視圖(CoordinatorLayout或者DecorView)
* @param text 文本
* @param duration 顯示時長
* @param textColor 文本顏色
* @param bgColor 背景色
* @param actionText 事件文本
* @param actionTextColor 事件文本顏色
* @param listener 監聽器
*/
private static void showSnackbar(View parent, CharSequence text, int duration, @ColorInt int textColor, @ColorInt int bgColor,
CharSequence actionText, int actionTextColor, View.OnClickListener listener) {
switch (duration) {
default:
case Snackbar.LENGTH_SHORT:
case Snackbar.LENGTH_LONG:
snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, text, duration));
break;
case Snackbar.LENGTH_INDEFINITE:
snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, text, Snackbar.LENGTH_INDEFINITE).setDuration(duration));
}
View view = snackbarWeakReference.get().getView();
((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(textColor);
view.setBackgroundColor(bgColor);
if (actionText != null && actionText.length() > 0 && listener != null) {
snackbarWeakReference.get().setActionTextColor(actionTextColor);
snackbarWeakReference.get().setAction(actionText, listener);
}
snackbarWeakReference.get().show();
}
示例5: setColor
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* 設置狀態欄顏色
*
* @param activity 需要設置的activity
* @param color 狀態欄顏色值
* @param statusBarAlpha 狀態欄透明度
*/
public static void setColor(Activity activity, @ColorInt int color, int statusBarAlpha) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
int count = decorView.getChildCount();
if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
decorView.getChildAt(count - 1).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
} else {
StatusBarView statusView = createStatusBarView(activity, color, statusBarAlpha);
decorView.addView(statusView);
}
setRootView(activity);
}
}
示例6: getColorShades
import android.support.annotation.ColorInt; //導入依賴的package包/類
private int[] getColorShades(@ColorInt int color) {
return new int[]{
shadeColor(color, 0.9),
shadeColor(color, 0.7),
shadeColor(color, 0.5),
shadeColor(color, 0.333),
shadeColor(color, 0.166),
shadeColor(color, -0.125),
shadeColor(color, -0.25),
shadeColor(color, -0.375),
shadeColor(color, -0.5),
shadeColor(color, -0.675),
shadeColor(color, -0.7),
shadeColor(color, -0.775),
};
}
示例7: getDarkColor
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* Get the dark color.
*
* @param color Original color.
* @return Dark color.
*/
@ColorInt
private static int getDarkColor(final int color) {
final float factor = 0.6f;
final int a = Color.alpha(color);
final int r = Math.round(Color.red(color) * factor);
final int g = Math.round(Color.green(color) * factor);
final int b = Math.round(Color.blue(color) * factor);
return Color.argb(a,
Math.min(r, 255),
Math.min(g, 255),
Math.min(b, 255));
}
示例8: setFillColor
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* Set a color to be drawn behind the circle-shaped drawable. Note that
* this has no effect if the drawable is opaque or no drawable is set.
*
* @param fillColor The color to be drawn behind the drawable
*
* @deprecated Fill color support is going to be removed in the future
*/
@Deprecated
public void setFillColor(@ColorInt int fillColor) {
if (fillColor == mFillColor) {
return;
}
mFillColor = fillColor;
mFillPaint.setColor(fillColor);
invalidate();
}
示例9: applySpan
import android.support.annotation.ColorInt; //導入依賴的package包/類
private void applySpan(Spannable spannable, @ColorInt int color, int start, int end) {
spannable.setSpan(
new ForegroundColorSpan(color),
start,
end,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
示例10: getColor
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* Gets color.
*
* @param context the context
* @param colorRes the color res
* @return the color
*/
@ColorInt
public static int getColor(Context context, @ColorRes int colorRes) {
if (Build.VERSION.SDK_INT < 21) {
//noinspection deprecation
return context.getResources().getColor(colorRes);
} else {
return context.getResources().getColor(colorRes, null);
}
}
示例11: calculateLuminance
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* Returns the luminance of a color as a float between {@code 0.0} and {@code 1.0}.
* <p>Defined as the Y component in the XYZ representation of {@code color}.</p>
*/
@FloatRange(from = 0.0, to = 1.0)
public static double calculateLuminance(@ColorInt int color) {
final double[] result = getTempDouble3Array();
colorToXYZ(color, result);
// Luminance is the Y component
return result[1] / 100;
}
示例12: getColorFromAttr
import android.support.annotation.ColorInt; //導入依賴的package包/類
@ColorInt
public static int getColorFromAttr(Context context, int attr, @ColorInt int defaultColor) {
TypedArray a = context.obtainStyledAttributes(new TypedValue().data, new int[]{attr});
int intColor = a.getColor(0, defaultColor);
a.recycle();
return intColor;
}
示例13: setFillColor
import android.support.annotation.ColorInt; //導入依賴的package包/類
public void setFillColor(@ColorInt int fillColor) {
if (fillColor == mFillColor) {
return;
}
mFillColor = fillColor;
mFillPaint.setColor(fillColor);
invalidate();
}
示例14: setColorAlpha
import android.support.annotation.ColorInt; //導入依賴的package包/類
@ColorInt
public static int setColorAlpha(@ColorInt int color, @FloatRange(from = 0.0D, to = 1.0D) float alpha) {
int alpha2 = Math.round((float) Color.alpha(color) * alpha);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return Color.argb(alpha2, red, green, blue);
}
示例15: setColor
import android.support.annotation.ColorInt; //導入依賴的package包/類
/**
* Sets the color of the drawable.
*/
public void setColor(@ColorInt int color) {
if (color != mPaint.getColor()) {
mPaint.setColor(color);
invalidateSelf();
}
}