项目:FastAndroid
文件:UIStatusBarController.java
/**
* 设置状态栏颜色
*
* @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);
}
}
项目:qmui
文件:QMUIDrawableHelper.java
/**
* 动态创建带上分隔线或下分隔线的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,top ? separatorHeight : 0,top ? 0 : separatorHeight);
return layerDrawable;
}
项目:RLibrary
文件:SnackbarUtils.java
/**
* 设置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,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,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();
}
项目:GitHub
文件:StatusBarUtil.java
/**
* 设置状态栏颜色
*
* @param activity 需要设置的activity
* @param color 状态栏颜色值
* @param statusBaralpha 状态栏透明度
*/
public static void setColor(Activity activity,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,statusBaralpha);
decorView.addView(statusView);
}
setRootView(activity);
}
}
项目:SubwayTooter
文件:ColorPickerDialog.java
private int[] getColorShades(@ColorInt int color) {
return new int[]{
shadeColor(color,0.9),shadeColor(color,0.7),0.5),0.333),0.166),-0.125),-0.25),-0.375),-0.5),-0.675),-0.7),-0.775),};
}
项目:EmoticonGIFKeyboard
文件:EmoticonGifImageView.java
/**
* 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,Math.min(b,255));
}
项目:chips-input-layout
文件:CircleImageView.java
/**
* 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();
}
private void applySpan(Spannable spannable,int start,int end) {
spannable.setSpan(
new ForegroundColorSpan(color),start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
项目:MainCalendar
文件:CompatUtils.java
/**
* 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);
}
}
项目:GitHub
文件:ColorUtils.java
/**
* 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;
}
项目:IslamicLibraryAndroid
文件:Util.java
@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;
}
项目:XERUNG
文件:CircleImageView.java
public void setFillColor(@ColorInt int fillColor) {
if (fillColor == mFillColor) {
return;
}
mFillColor = fillColor;
mFillPaint.setColor(fillColor);
invalidate();
}
项目:MusicX-music-player
文件:Helper.java
@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);
}
/**
* Sets the color of the drawable.
*/
public void setColor(@ColorInt int color) {
if (color != mPaint.getColor()) {
mPaint.setColor(color);
invalidateSelf();
}
}
项目:AndroidDigIn
文件:TouchDelegateViewGroup.java
public void setDelegateAreaColor(@ColorInt int color,Rect rect) {
paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(color);
this.rect = rect;
invalidate();
}
项目:GitHub
文件:BarUtils.java
/**
* 设置状态栏颜色
*
* @param fakeStatusBar 伪造状态栏
* @param color 状态栏颜色值
* @param alpha 状态栏透明度,此透明度并非颜色中的透明度
*/
public static void setStatusBarColor(@NonNull final View fakeStatusBar,@ColorInt final int color,to = 255) final int alpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
fakeStatusBar.setVisibility(View.VISIBLE);
transparentStatusBar((Activity) fakeStatusBar.getContext());
ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.height = BarUtils.getStatusBarHeight();
fakeStatusBar.setBackgroundColor(getStatusBarColor(color,alpha));
}
项目:MusicX-music-player
文件:ATEUtil.java
@ColorInt
public static int shiftColor(@ColorInt int color,@FloatRange(from = 0.0f,to = 2.0f) float by) {
if (by == 1f) return color;
float[] hsv = new float[3];
Color.colorToHSV(color,hsv);
hsv[2] *= by; // value component
return Color.HSVToColor(hsv);
}
项目:TakeRest
文件:FragmentUtils.java
项目:IslamicLibraryAndroid
文件:Highlight.java
@ColorInt
public static int getHighlightColor(String className) {
Matcher matcher = HIGHLIGHT_CLASS_PATTERN.matcher(className);
int classNumber = 0;
if (matcher.matches()) {
classNumber = Integer.parseInt(matcher.group(1));
}
return highlightColorMap.get(classNumber);
}
项目:GitHub
文件:StatusBarUtil.java
/**
* 生成一个和状态栏大小相同的彩色矩形条
*
* @param activity 需要设置的 activity
* @param color 状态栏颜色值
* @return 状态栏矩形条
*/
private static StatusBarView createStatusBarView(Activity activity,@ColorInt int color) {
// 绘制一个和状态栏一样高的矩形
StatusBarView statusBarView = new StatusBarView(activity);
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,getStatusBarHeight(activity));
statusBarView.setLayoutParams(params);
statusBarView.setBackgroundColor(color);
return statusBarView;
}
@Override
public View createView(ViewGroup root,float textSize,float textAlpha) {
View view = LayoutInflater.from(root.getContext()).inflate(layoutResId,root,false);
cpuUsageTextView = view.findViewById(R.id.debugoverlay_overlay_text);
cpuUsageTextView.setTextColor(textColor);
cpuUsageTextView.setTextSize(textSize);
cpuUsageTextView.setAlpha(textAlpha);
return view;
}
项目:emptyview
文件:EmptyView.java
private void setText(@Nullable CharSequence text,@ColorInt int color) {
if (TextUtils.isEmpty(text)) {
textView.setVisibility(GONE);
} else {
textView.setVisibility(VISIBLE);
textView.setText(fromHtml(text.toString()));
textView.setTextColor(color);
}
}
public void setBorderColor(@ColorInt int borderColor) {
if (borderColor == mBorderColor) {
return;
}
mBorderColor = borderColor;
mBorderPaint.setColor(mBorderColor);
invalidate();
}
项目:CXJPadProject
文件:WheelPicker.java
@CheckResult
@ColorInt
public static int navigationViewSelectedBg(@NonNull Context context,@Nullable String key,boolean darkTheme) {
final int defaultColor = ContextCompat.getColor(context,darkTheme ?
R.color.ate_navigation_drawer_selected_dark : R.color.ate_navigation_drawer_selected_light);
return prefs(context,key).getInt(KEY_NAVIGATIONVIEW_SELECTED_BG,defaultColor);
}
项目:CFAlertDialog
文件:CFAlertDialog.java
public CFAlertActionButton(Context context,String buttonText,@ColorInt int backgroundColor,CFAlertActionStyle style,CFAlertActionAlignment alignment,OnClickListener onClickListener) {
this.context = context;
this.buttonText = buttonText;
this.textColor = textColor;
this.backgroundColor = backgroundColor;
this.style = style;
this.backgroundDrawableId = getBackgroundDrawable(style);
this.alignment = alignment;
this.onClickListener = onClickListener;
// default textColor
if (textColor == -1) {
this.textColor = getTextColor(style);
}
}
项目:AnimatedArcProgressView
文件:ArcLoadingView.java
/**
* Setup primary color for the arcs.
* Basically initializes {@code mColorList} with provided color.
*
* @param color A {@link ColorInt}.
*/
protected void setPrimaryColor(@ColorInt int color) {
// clear color list and make it null,so it's ignored when drawing and primary color will be used instead
setColorList(null);
if (mPrimaryColor != color) {
mPrimaryColor = color;
}
}
项目:fluentAppBar
文件:MenuSecondaryItemsAdapter.java
MenuSecondaryItemsAdapter(Context context,@MenuRes int secondaryMenuId,View.OnClickListener onClickListener,@ColorInt int foregroundColour) {
this.context = context;
this.onClickListener = onClickListener;
this.foregroundColour = foregroundColour;
this.itemss = new ArrayList<>();
MenuParserHelper.parseMenu(context,secondaryMenuId,itemss);
}
项目:Readhub-Android
文件:ResUtils.java
@ColorInt
public static int getThemeAttrColor(@NonNull Context context,@AttrRes int attr) {
TypedArray a = context.obtainStyledAttributes(null,new int[]{attr});
try {
return a.getColor(0,0);
} finally {
a.recycle();
}
}
项目:Recognize-it
文件:AlbumUtils.java
/**
* Return a color-int from alpha,blue components.
*
* @param color color.
* @param alpha alpha,alpha component [0..255] of the color.
*/
@ColorInt
public static int getAlphaColor(@ColorInt int color,to = 255) int alpha) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return Color.argb(alpha,blue);
}
项目:FastLib
文件:FastLoadMoreView.java
public static noroot newInstance(String title,String description,@SuppressWarnings("SameParameterValue") @DrawableRes int drawable,@ColorInt int color) {
noroot fragment = new noroot();
Bundle args = new Bundle();
args.putString(ARG_TITLE,title);
args.putString(ARG_DESC,description);
args.putInt(ARG_DRAWABLE,drawable);
args.putInt(ARG_BG_COLOR,color);
fragment.setArguments(args);
return fragment;
}
项目:GitHub
文件:SpaceTabLayout.java
public void setTabOneTextColor(@ColorInt int tabOneTextColor) {
if (!iconOnly) tabOneTextView.setTextColor(tabOneTextColor);
else throw new IllegalArgumentException("You selected icons only.");
}
项目:CXJPadProject
文件:ConfirmPopup.java
public static Drawable tintDrawable(Drawable d,@ColorInt int color) {
Drawable wd = DrawableCompat.wrap(d);
DrawableCompat.setTint(wd,color);
return wd;
}
项目:ParticlesDrawable
文件:ParticlesDrawable.java
@Override
public void fillCircle(final float cx,final float cy,final float radius,@ColorInt final int color) {
mCanvasParticlesView.fillCircle(cx,cy,radius,color);
}
项目:GitHub
文件:SpaceTabLayout.java
public void setTabThreeTextColor(@ColorInt int tabThreeTextColor) {
if (!iconOnly) tabThreeTextView.setTextColor(tabThreeTextColor);
else throw new IllegalArgumentException("You selected icons only.");
}
项目:android-paypal-example
文件:BadgeStyle.java
项目:proSwipeButton
文件:ProSwipeButton.java
@ColorInt
public int getTextColor() {
return this.textColorInt;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。