android.graphics.drawable.shapes.RoundRectShape Java Examples
The following examples show how to use
android.graphics.drawable.shapes.RoundRectShape.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Label.java From FloatingActionButton with Apache License 2.0 | 6 votes |
private Drawable createRectDrawable(int color) { RoundRectShape shape = new RoundRectShape( new float[]{ mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius }, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(shape); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
Example #2
Source File: Utils.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
public static void setShadow(View view, Drawable sd) { RoundRectShape rss = new RoundRectShape(new float[]{12f, 12f, 12f, 12f, 12f, 12f, 12f, 12f}, null, null); ShapeDrawable sds = new ShapeDrawable(rss); sds.setShaderFactory(new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { LinearGradient lg = new LinearGradient(0, 0, 0, height, new int[]{Color.parseColor("#e5e5e5"), Color.parseColor("#e5e5e5"), Color.parseColor("#e5e5e5"), Color.parseColor("#e5e5e5")}, new float[]{0, 0.50f, 0.50f, 1}, Shader.TileMode.REPEAT); return lg; } }); LayerDrawable ld = new LayerDrawable(new Drawable[]{sds, sd}); ld.setLayerInset(0, 5, 5, 0, 0); // inset the shadow so it doesn't start right at the left/top ld.setLayerInset(1, 0, 0, 5, 5); // inset the top drawable so we can leave a bit of space for the shadow to use view.setBackgroundDrawable(ld); }
Example #3
Source File: BitmapUtil.java From Leanplum-Android-SDK with Apache License 2.0 | 6 votes |
private static Drawable getBackground(int normalStateColor, int pressedStateColor) { StateListDrawable background = new StateListDrawable(); int c = SizeUtil.dp10; float[] r = new float[] {c, c, c, c, c, c, c, c}; RoundRectShape rr = new RoundRectShape(r, null, null); ShapeDrawable cd = new ShapeDrawable(); cd.setShape(rr); cd.getPaint().setColor(pressedStateColor); background.addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_focused}, cd); background.addState(new int[] {-android.R.attr.state_pressed, android.R.attr.state_focused}, cd); background.addState(new int[] {android.R.attr.state_pressed, -android.R.attr.state_focused}, cd); ShapeDrawable cd1 = new ShapeDrawable(); cd1.setShape(rr); cd1.getPaint().setColor(normalStateColor); background.addState(new int[] {-android.R.attr.state_pressed, -android.R.attr.state_focused}, cd1); return background; }
Example #4
Source File: BadgeView.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
private ShapeDrawable a() { int i1 = a(8); float af[] = new float[8]; af[0] = i1; af[1] = i1; af[2] = i1; af[3] = i1; af[4] = i1; af[5] = i1; af[6] = i1; af[7] = i1; ShapeDrawable shapedrawable = new ShapeDrawable(new RoundRectShape(af, null, null)); shapedrawable.getPaint().setColor(n); return shapedrawable; }
Example #5
Source File: SUtils.java From SublimePicker with Apache License 2.0 | 6 votes |
public static Drawable createBgDrawable(int color, int rTopLeft, int rTopRight, int rBottomRight, int rBottomLeft) { float[] outerRadii = new float[8]; outerRadii[0] = rTopLeft; outerRadii[1] = rTopLeft; outerRadii[2] = rTopRight; outerRadii[3] = rTopRight; outerRadii[4] = rBottomRight; outerRadii[5] = rBottomRight; outerRadii[6] = rBottomLeft; outerRadii[7] = rBottomLeft; RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
Example #6
Source File: SUtils.java From SublimePicker with Apache License 2.0 | 6 votes |
private static Drawable createButtonShape(Context context, int color) { // Translation of Lollipop's xml button-bg definition to Java int paddingH = context.getResources() .getDimensionPixelSize(R.dimen.button_padding_horizontal_material); int paddingV = context.getResources() .getDimensionPixelSize(R.dimen.button_padding_vertical_material); int insetH = context.getResources() .getDimensionPixelSize(R.dimen.button_inset_horizontal_material); int insetV = context.getResources() .getDimensionPixelSize(R.dimen.button_inset_vertical_material); float[] outerRadii = new float[8]; Arrays.fill(outerRadii, CORNER_RADIUS); RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV); return new InsetDrawable(shapeDrawable, insetH, insetV, insetH, insetV); }
Example #7
Source File: LemonBubblePrivateAnimationTool.java From LemonBubble4Android with MIT License | 6 votes |
void setCornerRadius(View view, int radius, int color) { radius = _DP(radius); int borderWidth = 0;// 加边框后会出现空心圆角矩形的效果,所以设置为0 float[] outerRadius = new float[8]; float[] innerRadius = new float[8]; for (int i = 0; i < 8; i++) { outerRadius[i] = radius + borderWidth; innerRadius[i] = radius; } ShapeDrawable shapeDrawable = // 创建图形drawable new ShapeDrawable( // 创建圆角矩形 new RoundRectShape(outerRadius, new RectF(borderWidth, borderWidth, borderWidth, borderWidth), innerRadius)); shapeDrawable.getPaint().setColor(color);// 使用指定的颜色绘制,即背景颜色 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // 高版本SDK使用新的API view.setBackground(shapeDrawable); } else { view.setBackgroundDrawable(shapeDrawable); } }
Example #8
Source File: Label.java From clear-todolist with GNU General Public License v3.0 | 6 votes |
private Drawable createRectDrawable(int color) { RoundRectShape shape = new RoundRectShape( new float[]{ mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius }, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(shape); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
Example #9
Source File: Label.java From ShareBox with Apache License 2.0 | 6 votes |
private Drawable createRectDrawable(int color) { RoundRectShape shape = new RoundRectShape( new float[]{ mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius }, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(shape); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
Example #10
Source File: DrawableHelper.java From android-round-textview with Apache License 2.0 | 6 votes |
public static Drawable getCornerDrawable(float topLeft, float topRight, float bottomLeft, float bottomRight, @ColorInt int color) { float[] outerR = new float[8]; outerR[0] = topLeft; outerR[1] = topLeft; outerR[2] = topRight; outerR[3] = topRight; outerR[4] = bottomRight; outerR[5] = bottomRight; outerR[6] = bottomLeft; outerR[7] = bottomLeft; ShapeDrawable drawable = new ShapeDrawable(); drawable.setShape(new RoundRectShape(outerR, null, null)); drawable.getPaint().setColor(color); return drawable; }
Example #11
Source File: ThemeButton.java From talk-android with MIT License | 6 votes |
public void setThemeBackground(int color, int colorPressed) { int radius = DensityUtil.dip2px(getContext(), 2); float[] radii = new float[]{radius, radius, radius, radius, radius, radius, radius, radius}; StateListDrawable states = new StateListDrawable(); RoundRectShape disableShape = new RoundRectShape(radii, null, null); ShapeDrawable disableDrawable = new ShapeDrawable(disableShape); disableDrawable.getPaint().setColor(getResources().getColor(R.color.material_grey_300)); states.addState(new int[]{-android.R.attr.state_enabled}, disableDrawable); RoundRectShape pressedShape = new RoundRectShape(radii, null, null); ShapeDrawable pressedDrawable = new ShapeDrawable(pressedShape); pressedDrawable.getPaint().setColor(colorPressed); states.addState(new int[]{android.R.attr.state_pressed}, pressedDrawable); RoundRectShape normalShape = new RoundRectShape(radii, null, null); ShapeDrawable normalDrawable = new ShapeDrawable(normalShape); normalDrawable.getPaint().setColor(color); states.addState(new int[]{-android.R.attr.state_pressed}, normalDrawable); setBackgroundDrawable(states); }
Example #12
Source File: UEImage.java From Auie with GNU General Public License v2.0 | 5 votes |
/** * 生成图片 */ public static ShapeDrawable createBackground(int color, int alpha, float radius){ float[] outerR = new float[] { radius, radius, radius, radius, radius, radius, radius, radius }; RoundRectShape roundRectShape = new RoundRectShape(outerR, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); shapeDrawable.getPaint().setColor(color); shapeDrawable.getPaint().setAlpha(alpha); shapeDrawable.getPaint().setStyle(Paint.Style.FILL); return shapeDrawable; }
Example #13
Source File: RippleHelper.java From SegmentedButton with Apache License 2.0 | 5 votes |
private static Drawable getRippleMask(int color, int radius) { float[] outerRadii = new float[8]; Arrays.fill(outerRadii, radius); RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
Example #14
Source File: TextDrawable.java From ImageLetterIcon with Apache License 2.0 | 5 votes |
private void drawBorder(Canvas canvas) { RectF rect = new RectF(getBounds()); rect.inset(borderThickness / 2, borderThickness / 2); if (shape instanceof OvalShape) { canvas.drawOval(rect, borderPaint); } else if (shape instanceof RoundRectShape) { canvas.drawRoundRect(rect, radius, radius, borderPaint); } else { canvas.drawRect(rect, borderPaint); } }
Example #15
Source File: BadgeView.java From android-project-wo2b with Apache License 2.0 | 5 votes |
private ShapeDrawable getDefaultBackground() { int r = dipToPixels(DEFAULT_CORNER_RADIUS_DIP); float[] outerR = new float[] { r, r, r, r, r, r, r, r }; RoundRectShape rr = new RoundRectShape(outerR, null, null); ShapeDrawable drawable = new ShapeDrawable(rr); drawable.getPaint().setColor(badgeColor); return drawable; }
Example #16
Source File: ArrowBubbleDrawable.java From 365browser with Apache License 2.0 | 5 votes |
public ArrowBubbleDrawable(Context context) { mRadiusPx = context.getResources().getDimensionPixelSize(R.dimen.text_bubble_corner_radius); mArrowWidthPx = context.getResources().getDimensionPixelSize(R.dimen.text_bubble_arrow_width); mArrowHeightPx = context.getResources().getDimensionPixelSize(R.dimen.text_bubble_arrow_height); // Set up the arrow path and paint for drawing. mArrowPath = new Path(); mArrowPath.setFillType(Path.FillType.EVEN_ODD); mArrowPath.moveTo(-mArrowWidthPx / 2.f, mArrowHeightPx); mArrowPath.lineTo(0, 0); mArrowPath.lineTo(mArrowWidthPx / 2.f, mArrowHeightPx); mArrowPath.lineTo(-mArrowWidthPx / 2.f, mArrowHeightPx); mArrowPath.close(); mArrowPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mArrowPaint.setColor(Color.WHITE); mArrowPaint.setStyle(Paint.Style.FILL); mBubbleDrawable = new ShapeDrawable( new RoundRectShape(new float[] {mRadiusPx, mRadiusPx, mRadiusPx, mRadiusPx, mRadiusPx, mRadiusPx, mRadiusPx, mRadiusPx}, null, null)); mBubbleDrawable.setCallback(this); }
Example #17
Source File: TagFlowLayout.java From support with Apache License 2.0 | 5 votes |
protected Drawable newRoundRectShape(int color, int radius) { ShapeDrawable shape = new ShapeDrawable(new RoundRectShape(new float[]{radius, radius, radius, radius, radius, radius, radius, radius}, null, null)); shape.getPaint().setStyle(Paint.Style.FILL); shape.getPaint().setColor(color); shape.getPaint().setAntiAlias(true); return shape; }
Example #18
Source File: ViewHelper.java From FastAccess with GNU General Public License v3.0 | 5 votes |
private static Drawable getRippleMask(int color) { float[] outerRadii = new float[8]; Arrays.fill(outerRadii, 3); RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
Example #19
Source File: TextDrawable.java From NHentai-android with GNU General Public License v3.0 | 5 votes |
private void drawBorder(Canvas canvas) { RectF rect = new RectF(getBounds()); rect.inset(borderThickness/2, borderThickness/2); if (shape instanceof OvalShape) { canvas.drawOval(rect, borderPaint); } else if (shape instanceof RoundRectShape) { canvas.drawRoundRect(rect, radius, radius, borderPaint); } else { canvas.drawRect(rect, borderPaint); } }
Example #20
Source File: SpannableBar.java From SpannableBar with Apache License 2.0 | 5 votes |
/** * Set the bar's corner radius * * @param radius the radius to set */ public void setRadius(float radius) { this.radius = scaledDensity * radius + 0.5f; this.radii = new float[]{ radius, radius, radius, radius, radius, radius, radius, radius }; drawable = new ShapeDrawable(new RoundRectShape(radii, null, null)); invalidate(); }
Example #21
Source File: TextDrawable.java From ImageLetterIcon with Apache License 2.0 | 5 votes |
@Override public IBuilder roundRect(int radius) { this.radius = radius; float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius}; this.shape = new RoundRectShape(radii, null, null); return this; }
Example #22
Source File: TextDrawable.java From Muzesto with GNU General Public License v3.0 | 5 votes |
@Override public IBuilder roundRect(int radius) { this.radius = radius; float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius}; this.shape = new RoundRectShape(radii, null, null); return this; }
Example #23
Source File: PromptDialog.java From YuanNewsForAndroid with Apache License 2.0 | 5 votes |
private void setBottomCorners(View llBtnGroup) { int radius = DisplayUtil.dp2px(getContext(), DEFAULT_RADIUS); float[] outerRadii = new float[] { 0, 0, 0, 0, radius, radius, radius, radius }; RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); shapeDrawable.getPaint().setColor(Color.WHITE); shapeDrawable.getPaint().setStyle(Paint.Style.FILL); llBtnGroup.setBackgroundDrawable(shapeDrawable); }
Example #24
Source File: ThemeButton.java From talk-android with MIT License | 5 votes |
public void setThemeBackground() { Team team = (Team) MainApp.PREF_UTIL.getObject(Constant.TEAM, Team.class); String colorName = (team == null) ? Constant.DEFAULT_COLOR : team.getColor(); int radius = DensityUtil.dip2px(getContext(), 2); float[] radii = new float[]{radius, radius, radius, radius, radius, radius, radius, radius}; StateListDrawable states = new StateListDrawable(); RoundRectShape disableShape = new RoundRectShape(radii, null, null); ShapeDrawable disableDrawable = new ShapeDrawable(disableShape); disableDrawable.getPaint().setColor(getResources().getColor(R.color.material_grey_300)); states.addState(new int[]{-android.R.attr.state_enabled}, disableDrawable); int themeDarkColor = getResources().getColor(ThemeUtil.getThemeColorDarkRes(colorName)); RoundRectShape pressedShape = new RoundRectShape(radii, null, null); ShapeDrawable pressedDrawable = new ShapeDrawable(pressedShape); pressedDrawable.getPaint().setColor(themeDarkColor); states.addState(new int[]{android.R.attr.state_pressed}, pressedDrawable); RoundRectShape normalShape = new RoundRectShape(radii, null, null); ShapeDrawable normalDrawable = new ShapeDrawable(normalShape); int themeColor = ThemeUtil.getThemeColor(getResources(), colorName); normalDrawable.getPaint().setColor(themeColor); states.addState(new int[]{-android.R.attr.state_pressed}, normalDrawable); setBackgroundDrawable(states); }
Example #25
Source File: DrawableUtils.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
private static Drawable getRippleMask(@ColorInt int color) { float[] outerRadii = new float[8]; // 3 is the radius of final ripple, instead of 3 we can give required final radius Arrays.fill(outerRadii, 3); RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
Example #26
Source File: UIToast.java From Auie with GNU General Public License v2.0 | 5 votes |
private static ShapeDrawable createBackground(int color, float radius){ float[] outerR = new float[] { radius, radius, radius, radius, radius, radius, radius, radius }; RoundRectShape roundRectShape = new RoundRectShape(outerR, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); shapeDrawable.getPaint().setColor(color); shapeDrawable.getPaint().setStyle(Paint.Style.FILL); return shapeDrawable; }
Example #27
Source File: XulColorDrawable.java From starcor.xul with GNU Lesser General Public License v3.0 | 5 votes |
public XulColorDrawable(int color, int width, int height, float[] roundRectRadius) { this._color = color; this._width = width; this._height = height; _radius = roundRectRadius; if (_radius == null) { return; } if (_radius.length == 8) { _roundRectShape = new RoundRectShape(_radius, null, null); } }
Example #28
Source File: RFABShape.java From RapidFloatingActionButton with Apache License 2.0 | 5 votes |
public static ShapeDrawable generateCornerShapeDrawable(int color, int topLeftCorner, int topRightCorner, int bottomRightCorner, int bottomLeftCorner) { Shape shape = new RoundRectShape(new float[]{topLeftCorner, topLeftCorner, topRightCorner, topRightCorner, bottomRightCorner, bottomRightCorner, bottomLeftCorner, bottomLeftCorner}, null, null); ShapeDrawable sd = new ShapeDrawable(shape); sd.getPaint().setColor(color); sd.getPaint().setStyle(Paint.Style.FILL); return sd; }
Example #29
Source File: ButtonBase.java From appinventor-extensions with Apache License 2.0 | 5 votes |
private void setShape() { ShapeDrawable drawable = new ShapeDrawable(); // Set shape of drawable. switch (shape) { case Component.BUTTON_SHAPE_ROUNDED: drawable.setShape(new RoundRectShape(ROUNDED_CORNERS_ARRAY, null, null)); break; case Component.BUTTON_SHAPE_RECT: drawable.setShape(new RectShape()); break; case Component.BUTTON_SHAPE_OVAL: drawable.setShape(new OvalShape()); break; default: throw new IllegalArgumentException(); } // Set drawable to the background of the button. if (!AppInventorCompatActivity.isClassicMode() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ViewUtil.setBackgroundDrawable(view, new RippleDrawable(createRippleState(), drawable, drawable)); } else { ViewUtil.setBackgroundDrawable(view, drawable); } if (backgroundColor == Component.COLOR_NONE) { view.getBackground().setColorFilter(backgroundColor, PorterDuff.Mode.CLEAR); } else if (backgroundColor == Component.COLOR_DEFAULT) { view.getBackground().setColorFilter(SHAPED_DEFAULT_BACKGROUND_COLOR, PorterDuff.Mode.SRC_ATOP); } else { view.getBackground().setColorFilter(backgroundColor, PorterDuff.Mode.SRC_ATOP); } view.invalidate(); }
Example #30
Source File: RFABShape.java From RapidFloatingActionButton with Apache License 2.0 | 5 votes |
public static ShapeDrawable generateCornerStrokeDrawable(int color, float width, int topLeftCorner, int topRightCorner, int bottomRightCorner, int bottomLeftCorner) { Shape shape = new RoundRectShape(new float[]{topLeftCorner, topLeftCorner, topRightCorner, topRightCorner, bottomRightCorner, bottomRightCorner, bottomLeftCorner, bottomLeftCorner}, null, null); ShapeDrawable sd = new ShapeDrawable(shape); sd.getPaint().setColor(color); sd.getPaint().setStyle(Paint.Style.STROKE); sd.getPaint().setAntiAlias(true); sd.getPaint().setStrokeWidth(width); return sd; }