private Drawable getPressedEffectBeforeLollipop(CORNER_POSITION cornerPosition, int color) {
ShapeDrawable colorDrawablePressed = getCornerStateDrawable(cornerPosition);
colorDrawablePressed.getPaint().setColor(color);
colorDrawablePressed.getPaint().setStyle(Paint.Style.FILL);
colorDrawablePressed.getPaint().setAlpha(PRESSED_ALPHA_VALUE);
colorDrawablePressed.mutate();
StateListDrawable textBgDrawable = new StateListDrawable();
textBgDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, colorDrawablePressed);
return textBgDrawable;
}
java类android.graphics.drawable.ShapeDrawable的实例源码
ResHelper.java 文件源码
项目:SingleSelectBar
阅读 41
收藏 0
点赞 0
评论 0
CircleProgressBar.java 文件源码
项目:Multi-SwipeToRefreshLayout
阅读 31
收藏 0
点赞 0
评论 0
/**
* Update the background color of the mBgCircle image view.
*/
public void setBackgroundColor(@ColorRes int colorRes) {
if (getBackground() instanceof ShapeDrawable) {
((ShapeDrawable) getBackground())
.getPaint()
.setColor(getResources().getColor(colorRes));
}
}
MaterialProgressDrawable.java 文件源码
项目:Swface
阅读 35
收藏 0
点赞 0
评论 0
private void setUp(final double diameter) {
PtrLocalDisplay.init(mParent.getContext());
final int shadowYOffset = PtrLocalDisplay.dp2px(Y_OFFSET);
final int shadowXOffset = PtrLocalDisplay.dp2px(X_OFFSET);
int mShadowRadius = PtrLocalDisplay.dp2px(SHADOW_RADIUS);
OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter);
mShadow = new ShapeDrawable(oval);
if (Build.VERSION.SDK_INT >= 11) {
mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint());
}
mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
}
MaterialProgressDrawable.java 文件源码
项目:SmoothRefreshLayout
阅读 35
收藏 0
点赞 0
评论 0
private void setUp(final double diameter) {
final int shadowYOffset = PixelUtl.dp2px(mParent.getContext(), Y_OFFSET);
final int shadowXOffset = PixelUtl.dp2px(mParent.getContext(), X_OFFSET);
int mShadowRadius = PixelUtl.dp2px(mParent.getContext(), SHADOW_RADIUS);
OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter);
mShadow = new ShapeDrawable(oval);
if (Build.VERSION.SDK_INT >= 11) {
mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint());
}
mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
}
ResUtil.java 文件源码
项目:RLibrary
阅读 36
收藏 0
点赞 0
评论 0
public static Drawable generateCircleBgDrawable(float width, int color) {
Shape arcShape = new ArcShape(0, 360);
ShapeDrawable shopDrawablePress = new ShapeDrawable(arcShape);//圆形shape
shopDrawablePress.getPaint().setColor(color);//设置颜色
shopDrawablePress.getPaint().setStyle(Paint.Style.STROKE);//设置颜色
shopDrawablePress.getPaint().setStrokeWidth(width);//设置颜色
return shopDrawablePress;
}
ResUtil.java 文件源码
项目:RLibrary
阅读 26
收藏 0
点赞 0
评论 0
/**
* 创建一个框框的Drawable
*/
public static Drawable createStrokeDrawable(int color, float radii, float borderWidth) {
float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);
Shape roundRectShape = new RoundRectShape(outRadii, inset, outRadii);//圆角背景
ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape);//圆角shape
shapeDrawable.getPaint().setColor(color);//设置颜色
return shapeDrawable;
}
GmRipple.java 文件源码
项目:GmArchMvvm
阅读 27
收藏 0
点赞 0
评论 0
@NonNull
public static Drawable getSelectableDrawableFor(int color) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(
new int[]{android.R.attr.state_pressed},
new ColorDrawable(lightenOrDarken(color, 0.40D))
);
stateListDrawable.addState(
new int[]{android.R.attr.state_focused},
new ColorDrawable(lightenOrDarken(color, 0.80D))
);
stateListDrawable.addState(
new int[]{},
new ColorDrawable(color)
);
return stateListDrawable;
} else {
ColorStateList pressedColor = ColorStateList.valueOf(lightenOrDarken(color, 0.4D));
ColorDrawable defaultColor = new ColorDrawable(color);
ShapeDrawable shapeDrawable = (ShapeDrawable) getShapeWithColor(color);
Drawable rippleColor = getRippleColor(color);
return new RippleDrawable(
pressedColor,
shapeDrawable,
rippleColor
);
}
}
FloatingActionButtonLibrary.java 文件源码
项目:MyCalendar
阅读 32
收藏 0
点赞 0
评论 0
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
if (!mStrokeVisible) {
return new ColorDrawable(Color.TRANSPARENT);
}
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
final int bottomStrokeColor = darkenColor(color);
final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
final int topStrokeColor = lightenColor(color);
final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
final Paint paint = shapeDrawable.getPaint();
paint.setAntiAlias(true);
paint.setStrokeWidth(strokeWidth);
paint.setStyle(Style.STROKE);
shapeDrawable.setShaderFactory(new ShaderFactory() {
@Override
public Shader resize(int width, int height) {
return new LinearGradient(width / 2, 0, width / 2, height,
new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor },
new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f },
TileMode.CLAMP
);
}
});
return shapeDrawable;
}
TabLayoutUtil.java 文件源码
项目:RLibrary
阅读 22
收藏 0
点赞 0
评论 0
public static void setCommonTabDivider(CommonTabLayout tabLayout, @ColorInt int color, int showDividers, int padding) {
LinearLayout linearLayout = (LinearLayout) tabLayout.getChildAt(0);
linearLayout.setDividerPadding(padding);
RectShape rectShape = new RectShape();
float density = tabLayout.getResources().getDisplayMetrics().density;
ShapeDrawable shapeDrawable = new ShapeDrawable(rectShape);
shapeDrawable.setIntrinsicWidth((int) density);
shapeDrawable.setIntrinsicHeight((int) density);
shapeDrawable.getPaint().setColor(color);
shapeDrawable.getPaint().setStyle(Paint.Style.STROKE);
linearLayout.setDividerDrawable(shapeDrawable);
linearLayout.setShowDividers(showDividers);
}
MyConfig.java 文件源码
项目:CalendarPicker
阅读 35
收藏 0
点赞 0
评论 0
public static void setDrawableColor(Drawable v, Integer customColor){
if(customColor != null) {
if (v instanceof ShapeDrawable) {
((ShapeDrawable)v).getPaint().setColor(customColor);
} else if (v instanceof GradientDrawable) {
((GradientDrawable)v).setColor(customColor);
} else if (v instanceof ColorDrawable) {
((ColorDrawable)v).setColor(customColor);
}
}
}