本文整理汇总了Java中android.graphics.drawable.GradientDrawable.setCornerRadii方法的典型用法代码示例。如果您正苦于以下问题:Java GradientDrawable.setCornerRadii方法的具体用法?Java GradientDrawable.setCornerRadii怎么用?Java GradientDrawable.setCornerRadii使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.GradientDrawable
的用法示例。
在下文中一共展示了GradientDrawable.setCornerRadii方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public Drawable create(Context context) {
final GradientDrawable bubble = new GradientDrawable();
final int radius = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
final float[] radii = cornerBooleansToRadii(corners, radius);
bubble.setColor(color);
bubble.setCornerRadii(radii);
if (!hasShadow) {
return bubble;
} else {
final GradientDrawable shadow = new GradientDrawable();
final int distance = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_shadow_distance);
shadow.setColor(shadowColor);
shadow.setCornerRadii(radii);
final LayerDrawable layers = new LayerDrawable(new Drawable[]{shadow, bubble});
layers.setLayerInset(1, 0, 0, 0, distance);
return layers;
}
}
示例2: getGradientDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private Drawable getGradientDrawable(float mCornerRadius,
int mStrokeColor, int mSolidColor, int mStrokeWidth,
float mDashWidth, float mDashGap,
float mTopLeftRadius, float mTopRightRadius,
float mBottomLeftRadius, float mBottomRightRadius) {
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColor(mSolidColor);
gradientDrawable.setStroke(mStrokeWidth, mStrokeColor, mDashWidth, mDashGap);
float[] radius = {mTopLeftRadius, mTopLeftRadius, mTopRightRadius, mTopRightRadius, mBottomRightRadius,
mBottomRightRadius, mBottomLeftRadius, mBottomLeftRadius};
if (mCornerRadius == DEFAULT_CORNER_RADIUS) {
gradientDrawable.setCornerRadii(radius);
} else {
gradientDrawable.setCornerRadius(mCornerRadius);
}
return gradientDrawable;
}
示例3: setupGradientDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void setupGradientDrawable(View view, float mCornerRadius,
int mStrokeColor, int mSolidColor, int mStrokeWidth,
float mDashWidth, float mDashGap,
float mTopLeftRadius, float mTopRightRadius,
float mBottomLeftRadius, float mBottomRightRadius) {
mGradientDrawable = new GradientDrawable();
mGradientDrawable.setColor(mSolidColor);
mGradientDrawable.setStroke(mStrokeWidth, mStrokeColor, mDashWidth, mDashGap);
float[] radius = {mTopLeftRadius, mTopLeftRadius, mTopRightRadius, mTopRightRadius, mBottomRightRadius,
mBottomRightRadius, mBottomLeftRadius, mBottomLeftRadius};
if (mCornerRadius == DEFAULT_CORNER_RADIUS) {
mGradientDrawable.setCornerRadii(radius);
} else {
mGradientDrawable.setCornerRadius(mCornerRadius);
}
view.setBackgroundDrawable(mGradientDrawable);
}
示例4: setDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 设置 背景Drawable颜色线框色及圆角值
*
* @param gd
* @param color
* @param strokeColor
*/
private void setDrawable(GradientDrawable gd, int color, int strokeColor) {
//任意值大于0执行
if (topLeftRadius > 0 || topRightRadius > 0 || bottomRightRadius > 0 || bottomLeftRadius > 0) {
radiusArr[0] = topLeftRadius;
radiusArr[1] = topLeftRadius;
radiusArr[2] = topRightRadius;
radiusArr[3] = topRightRadius;
radiusArr[4] = bottomRightRadius;
radiusArr[5] = bottomRightRadius;
radiusArr[6] = bottomLeftRadius;
radiusArr[7] = bottomLeftRadius;
gd.setCornerRadii(radiusArr);
} else {
gd.setCornerRadius(radius);
}
gd.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeDashGap);
gd.setColor(color);
}
示例5: updateDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void updateDrawable(int strokeColor) {
int mbackgroundColor;
if (isChecked) {
mbackgroundColor = selectedBackgroundColor;
} else {
mbackgroundColor = backgroundColor;
}
GradientDrawable drawable = new GradientDrawable();
drawable.setCornerRadii(mRadius);
drawable.setColor(mbackgroundColor);
drawable.setStroke(mStrokeWidth, strokeColor);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
this.setBackgroundDrawable(drawable);
} else {
this.setBackground(drawable);
}
}
示例6: rebuildBackgroundShape
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* Rebuild the background shape based on config properties
*/
private void rebuildBackgroundShape() {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadii(getCornerRadii());
shape.setColor(mFillColor);
shape.setStroke(mStrokeWidth, mStrokeColor);
setBackgroundDrawable(shape);
}
示例7: createTileShape
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private static Drawable createTileShape(int backgroundColor, int borderColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadii(new float[]{7, 7, 7, 7, 0, 0, 0, 0});
shape.setColor(backgroundColor);
shape.setStroke(1, borderColor);
shape.setBounds(7, 7, 7, 7);
return (shape);
}
示例8: createDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private Drawable createDrawable(Drawable drawable, int backgroundColor, int borderColor, boolean forceToColorMode) {
if (!(drawable instanceof GradientDrawable) && !forceToColorMode) {
return drawable;
}
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColor(backgroundColor);
gradientDrawable.setStroke(mBdWidth, borderColor, mBdDashWidth, mBdDashGap);
if (mCRTopLeft == mCRTopRight
&& mCRTopRight == mCRBottomRight
&& mCRBottomRight == mCRBottomLeft) {
gradientDrawable.setCornerRadius(mCRTopLeft);
} else {
float[] cornerArray = new float[8];
cornerArray[0] = mCRTopLeft;
cornerArray[1] = mCRTopLeft;
cornerArray[2] = mCRTopRight;
cornerArray[3] = mCRTopRight;
cornerArray[4] = mCRBottomRight;
cornerArray[5] = mCRBottomRight;
cornerArray[6] = mCRBottomLeft;
cornerArray[7] = mCRBottomLeft;
gradientDrawable.setCornerRadii(cornerArray);
}
return gradientDrawable;
}
示例9: CT
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public CT(Builder builder) {
LayoutInflater inflater = (LayoutInflater) builder.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_layout, null);
TextView tv = layout.findViewById(R.id.cltv);
tv.setText(builder.text);
tv.setTextColor(builder.textCol);
ImageView iv = layout.findViewById(R.id.cliv);
iv.setImageResource(builder.imageRes);
GradientDrawable shape = new GradientDrawable();
shape.setShape(builder.shape);
shape.setCornerRadii(new float[]{
builder.radiusTopLeft,
builder.radiusTopLeft,
builder.radiusTopRight,
builder.radiusTopRight,
builder.radiusBottomRight,
builder.radiusBottomRight,
builder.radiusBottomLeft,
builder.radiusBottomLeft
});
shape.setColor(builder.backCol);
shape.setStroke(builder.borderWidth, builder.borderCol);
layout.setBackgroundDrawable(shape);
Toast toast = new Toast(builder.context);
toast.setView(layout);
toast.setDuration(builder.toastDuration);
toast.setGravity(builder.toastGravity,0,100);
toast.show();
}
示例10: getCornerDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private Drawable getCornerDrawable(boolean selected, float[] cornerRadii) {
GradientDrawable drawable = new GradientDrawable();
drawable.setColor(selected ? colorSelected : colorUnselected);
drawable.setCornerRadii(cornerRadii);
drawable.setStroke(strokeWidth, colorSelected);
return drawable;
}
示例11: initView
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void initView(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundLatout);
//显示类型
int shapeTpe = a.getInt(R.styleable.RoundLatout_viewShapeTpe, shapeTypes[0]);
//圆角大小
float cornerRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewCornerRadius, 0);
float topLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopLeftRadius, 0);
float topRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopRightRadius, 0);
float bottomLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomLeftRadius, 0);
float bottomRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomRightRadius, 0);
//填充色
int solidColor = a.getColor(R.styleable.RoundLatout_viewSolidColor, 0x0);
//边框
int strokeColor = a.getColor(R.styleable.RoundLatout_viewStrokeColor, 0x0);
int strokeWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeWidth, 0);
int strokeDashWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashWidth, 0);
int strokeDashGap = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashGap, 0);
a.recycle();
GradientDrawable gd = new GradientDrawable();
gd.setColor(solidColor);
//设置类型
gd.setShape(shapeTypes[shapeTpe]);
//类型为矩形才可设置圆角
if (shapeTypes[shapeTpe] == GradientDrawable.RECTANGLE) {
if (cornerRadius != 0) {
gd.setCornerRadius(cornerRadius);
} else {
gd.setCornerRadii(new float[]{topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius});
}
}
gd.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeDashGap);
setBackground(gd);
}
示例12: setBackground
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public static Drawable setBackground(View v, int color, int borderColor, int r, int borderStroke) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadii(new float[] { r, r, r, r, r, r, r, r });
shape.setColor(color);
shape.setStroke(borderStroke, borderColor);
return shape;
}
示例13: cornerDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public static Drawable cornerDrawable(final int bgColor, float[] cornerradius) {
final GradientDrawable bg = new GradientDrawable();
bg.setCornerRadii(cornerradius);
bg.setColor(bgColor);
return bg;
}
示例14: initData
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void initData(Context context, AttributeSet attrs) {
setClickable(true);
normalTextColor = getCurrentTextColor();
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShapeView);
touchTextColor = a.getColor(R.styleable.ShapeView_touchTextColor, getCurrentTextColor());
solidColor = a.getColor(R.styleable.ShapeView_solidColor, Color.GRAY);
stroke_Color = a.getColor(R.styleable.ShapeView_stroke_Color, Color.TRANSPARENT);
touchColor = a.getColor(R.styleable.ShapeView_touchSolidColor, Color.TRANSPARENT);
enableColor = a.getColor(R.styleable.ShapeView_enableColor, solidColor);
enableTextColor = a.getColor(R.styleable.ShapeView_enableTextColor, getCurrentTextColor());
cornesRadius = (int) a.getDimension(R.styleable.ShapeView_cornesRadius, 0);
topLeftRadius = (int) a.getDimension(R.styleable.ShapeView_topLeftRadius, 0);
topRightRadius = (int) a.getDimension(R.styleable.ShapeView_topRightRadius, 0);
bottomLeftRadius = (int) a.getDimension(R.styleable.ShapeView_bottomLeftRadius, 0);
bottomRightRadius = (int) a.getDimension(R.styleable.ShapeView_bottomRightRadius, 0);
stroke_Width = (int) a.getDimension(R.styleable.ShapeView_stroke_Width, 0);
strokeDashWidth = (int) a.getDimension(R.styleable.ShapeView_strokeDashWidth, 0);
strokeDashGap = (int) a.getDimension(R.styleable.ShapeView_strokeDashGap, 0);
shapeType = a.getInt(R.styleable.ShapeView_shapeType, -1);
gradientDrawable = new GradientDrawable();
gradientDrawable.setStroke(stroke_Width, stroke_Color, strokeDashWidth, strokeDashGap);
if (!isEnabled()) {
gradientDrawable.setColor(enableColor);
setTextColor(enableTextColor);
} else {
gradientDrawable.setColor(solidColor);
setTextColor(normalTextColor);
}
if (shapeType != -1) {
gradientDrawable.setShape(shapeType);
}
if (shapeType != GradientDrawable.OVAL) {
if (cornesRadius != 0) {
gradientDrawable.setCornerRadius(cornesRadius);
} else {
//1、2两个参数表示左上角,3、4表示右上角,5、6表示右下角,7、8表示左下角
gradientDrawable.setCornerRadii(new float[]{topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius});
}
}
setBackgroundDrawable(gradientDrawable);
}
示例15: initView
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void initView(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundLatout);
//显示类型
int shapeTpe = a.getInt(R.styleable.RoundLatout_viewShapeTpe, shapeTypes[0]);
//圆角大小
float cornerRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewCornerRadius, 0);
float topLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopLeftRadius, 0);
float topRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopRightRadius, 0);
float bottomLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomLeftRadius, 0);
float bottomRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomRightRadius, 0);
//填充色
int solidColor = a.getColor(R.styleable.RoundLatout_viewSolidColor, 0x0);
//边框
int strokeColor = a.getColor(R.styleable.RoundLatout_viewStrokeColor, 0x0);
int strokeWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeWidth, 0);
int strokeDashWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashWidth, 0);
int strokeDashGap = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashGap, 0);
a.recycle();
GradientDrawable gd = new GradientDrawable();
gd.setColor(solidColor);
//设置类型
gd.setShape(shapeTypes[shapeTpe]);
//类型为矩形才可设置圆角
if (shapeTypes[shapeTpe] == GradientDrawable.RECTANGLE) {
if (cornerRadius != 0) {
gd.setCornerRadius(cornerRadius);
} else {
gd.setCornerRadii(new float[]{topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius});
}
}
gd.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeDashGap);
setBackground(gd);
}