本文整理汇总了Java中android.graphics.drawable.shapes.RoundRectShape类的典型用法代码示例。如果您正苦于以下问题:Java RoundRectShape类的具体用法?Java RoundRectShape怎么用?Java RoundRectShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RoundRectShape类属于android.graphics.drawable.shapes包,在下文中一共展示了RoundRectShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: roundBitmap
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
public static Bitmap roundBitmap(Bitmap bitmap, int i, int i2, float f, float f2, float f3,
float f4) throws Throwable {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Rect rect = new Rect(0, 0, width, height);
Bitmap createBitmap = (width == i && height == i2) ? Bitmap.createBitmap(bitmap.getWidth
(), bitmap.getHeight(), Config.ARGB_8888) : Bitmap.createBitmap(i, i2, Config
.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
Paint paint = new Paint();
Rect rect2 = new Rect(0, 0, i, i2);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(-12434878);
float[] fArr = new float[]{f, f, f2, f2, f3, f3, f4, f4};
ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(fArr, new RectF(0.0f,
0.0f, 0.0f, 0.0f), fArr));
shapeDrawable.setBounds(rect2);
shapeDrawable.draw(canvas);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect2, paint);
return createBitmap;
}
示例2: getCornerDrawable
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
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;
}
示例3: createRectDrawable
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
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;
}
示例4: onBindViewHolder
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
RestTest restTest = datas.get(position);
RoundRectShape shape = new RoundRectShape(new float[]{8, 8, 8, 8, 8, 8, 8, 8}, null, null);
ShapeDrawable drawable = new ShapeDrawable(shape);
String color = "6bbd5b";
switch (restTest.getMethod().toUpperCase()) {
case "GET":
break;
case "POST":
color = "248fb2";
break;
case "DELETE":
color = "e27a7a";
break;
case "PUT":
color = "9b708b";
break;
}
drawable.getPaint().setColor(Color.parseColor("#" + color));
holder.tv.setBackground(drawable);
holder.tv.setText(restTest.getMethod().toUpperCase());
holder.spec.setText(restTest.getUrl());
}
示例5: getBackground
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
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;
}
示例6: createDefaultOverButtonBgDrawable
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
private StateListDrawable createDefaultOverButtonBgDrawable() {
int dp12 = (int) ThemeUtils.applyDimensionDp(this, 12.f);
int dp8 = (int) ThemeUtils.applyDimensionDp(this, 8.f);
float dp4 = ThemeUtils.applyDimensionDp(this, 4.f);
float[] round = new float[]{dp4, dp4, dp4, dp4, dp4, dp4, dp4, dp4};
ShapeDrawable pressedDrawable = new ShapeDrawable(new RoundRectShape(round, null, null));
pressedDrawable.setPadding(dp12, dp8, dp12, dp8);
int pressedColor = ThemeUtils.resolveColor(this, R.attr.gallery_toolbar_over_button_pressed_color, R.color.gallery_default_toolbar_over_button_pressed_color);
pressedDrawable.getPaint().setColor(pressedColor);
int normalColor = ThemeUtils.resolveColor(this, R.attr.gallery_toolbar_over_button_normal_color, R.color.gallery_default_toolbar_over_button_normal_color);
ShapeDrawable normalDrawable = new ShapeDrawable(new RoundRectShape(round, null, null));
normalDrawable.setPadding(dp12, dp8, dp12, dp8);
normalDrawable.getPaint().setColor(normalColor);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, pressedDrawable);
stateListDrawable.addState(new int[]{}, normalDrawable);
return stateListDrawable;
}
示例7: setCornerRadius
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
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);
}
}
示例8: getShape
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
private static RoundRectShape getShape(ATableView tableView, ATableViewCellBackgroundStyle backgroundStyle) {
ATableViewStyle tableStyle = tableView.getStyle();
float[] radius = new float[]{0, 0, 0, 0, 0, 0, 0, 0};
if (tableStyle == ATableViewStyle.Grouped) {
Resources res = tableView.getResources();
float radii = Math.round(res.getDimension(R.dimen.atv_grouped_stroke_radius));
if (backgroundStyle == ATableViewCellBackgroundStyle.Single) {
radius = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};
} else if (backgroundStyle == ATableViewCellBackgroundStyle.Top) {
radius = new float[]{radii, radii, radii, radii, 0, 0, 0, 0};
} else if (backgroundStyle == ATableViewCellBackgroundStyle.Bottom) {
radius = new float[]{0, 0, 0, 0, radii, radii, radii, radii};
}
}
return new RoundRectShape(radius, null, null);
}
示例9: setShape
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
private void setShape() {
ShapeDrawable drawable = new ShapeDrawable();
// Set color of drawable.
drawable.getPaint().setColor((backgroundColor == Component.COLOR_DEFAULT)
? SHAPED_DEFAULT_BACKGROUND_COLOR : backgroundColor);
// 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.
view.setBackgroundDrawable(drawable);
view.invalidate();
}
示例10: generateRoundDrawable
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
/**
* Generate bg drawable drawable.
*
* @param pressColor the press color
* @param defaultColor the default color
* @return the drawable
*/
public static Drawable generateRoundDrawable(float radii, int pressColor, int defaultColor) {
//圆角
Shape roundRectShape = new RoundRectShape(new float[]{radii, radii, radii, radii, radii, radii, radii, radii}, null, null);//圆角背景
//按下状态
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
shopDrawablePress.getPaint().setColor(pressColor);//设置颜色
//正常状态
ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShape);
shopDrawableNormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, shopDrawablePress);
bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态
return bgStateDrawable;
}
示例11: generateBorderDrawable
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
/**
* 正常 圆角边框;
* 按下 圆角色块
*/
public static Drawable generateBorderDrawable(float radii, float borderWidth, int pressColor, int defaultColor) {
//外环的圆角矩形
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, null, null);//圆角背景
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
shopDrawablePress.getPaint().setColor(pressColor);//设置颜色
//正常状态
Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, outRadii);
ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
shopDrawableNormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态
return bgStateDrawable;
}
示例12: toRoundCornerMutableBitmap
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
private static Bitmap toRoundCornerMutableBitmap(Canvas canvas, Paint paintClear, Bitmap srcBitmap, float[] roundRadius) {
canvas.setBitmap(srcBitmap);
RectF inset = new RectF(1, 1, 1, 1);
if (roundRadius.length == 2) {
float[] tmpRoundRadius = new float[8];
for (int i = 0; i < 4; ++i) {
tmpRoundRadius[i * 2 + 0] = roundRadius[0];
tmpRoundRadius[i * 2 + 1] = roundRadius[1];
roundRadius = tmpRoundRadius;
}
}
canvas.save();
canvas.translate(-1, -1);
RoundRectShape roundRectShape = new RoundRectShape(null, inset, roundRadius);
roundRectShape.resize(srcBitmap.getWidth() + 2, srcBitmap.getHeight() + 2);
roundRectShape.draw(canvas, paintClear);
canvas.restore();
canvas.setBitmap(null);
return srcBitmap;
}
示例13: setThemeBackground
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
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);
}
示例14: createRectDrawable
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
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;
}
示例15: getShapeDrawable
import android.graphics.drawable.shapes.RoundRectShape; //导入依赖的package包/类
@NonNull
private ShapeDrawable getShapeDrawable(int topLeftAndRightRadius, int bottomLeftAndRightRadius, int bgColor) {
float outRectr[] = new float[]{
topLeftAndRightRadius, topLeftAndRightRadius,
topLeftAndRightRadius, topLeftAndRightRadius,
bottomLeftAndRightRadius, bottomLeftAndRightRadius,
bottomLeftAndRightRadius, bottomLeftAndRightRadius};
/**
* 注意StateListDrawable的构造方法我们这里使用的
* 是第一参数它是一个float的数组保存的是圆角的半径,它是按照top-left顺时针保存的八个值
*/
//创建圆弧形状
RoundRectShape rectShape = new RoundRectShape(outRectr, null, null);
//创建drawable
ShapeDrawable pressedDrawable = new ShapeDrawable(rectShape);
//设置背景的颜色
pressedDrawable.getPaint().setColor(bgColor);
return pressedDrawable;
}