本文整理汇总了Java中android.graphics.drawable.GradientDrawable.setCornerRadius方法的典型用法代码示例。如果您正苦于以下问题:Java GradientDrawable.setCornerRadius方法的具体用法?Java GradientDrawable.setCornerRadius怎么用?Java GradientDrawable.setCornerRadius使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.GradientDrawable
的用法示例。
在下文中一共展示了GradientDrawable.setCornerRadius方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initBorder
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void initBorder() {
// if (mWipeOffBorder || mIdentity == null || !mIdentity.officialMember) {
// mDrawable = null;
// setBackground(null);
// return;
// }
if (mDrawable == null) {
float radius = 4f;
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
gradientDrawable.setShape(GradientDrawable.RECTANGLE);
gradientDrawable.setDither(true);
gradientDrawable.setStroke(STROKE_SIZE, mColor);
gradientDrawable.setCornerRadius(radius);
mDrawable = gradientDrawable;
} else {
mDrawable.setStroke(STROKE_SIZE, mColor);
}
setBackground(mDrawable);
}
示例2: inflateTextView
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private TextView inflateTextView() {
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(8);
shape.setColor(0xff000000 | mRandom.nextInt(0x00ffffff));
TextView textView = new TextView(this);
textView.setGravity(Gravity.CENTER);
textView.setTextColor(Color.WHITE);
textView.setWidth(150 + mRandom.nextInt(3) * 50);
textView.setHeight(150 + mRandom.nextInt(3) * 50);
textView.setTextSize(32);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
textView.setBackgroundDrawable(shape);
} else {
textView.setBackground(shape);
}
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
mList.removeViewWithAnimation(view);
}
});
textView.setText(String.format(Locale.JAPAN, "%1$02d", mCounter++));
return textView;
}
示例3: setButton
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
static void setButton(@ColorInt int bgColor, @ColorInt int color, Button button, boolean colored) {
if (!colored) {
if (bgColor!=-1)
color = bgColor;
else
color = Color.parseColor("#ffffff");
}
int selectedColor = isColorLight(color) ?
ColorUtils.blendARGB(color, Color.parseColor("#000000"), 0.15f) :
ColorUtils.blendARGB(color, Color.parseColor("#FFFFFF"), 0.20f);
GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP,
new int[]{selectedColor, selectedColor});
GradientDrawable drawable2 = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP,
new int[]{color, color});
drawable.setCornerRadius(dpToPx(2));
drawable2.setCornerRadius(dpToPx(2));
StateListDrawable button1bg = new StateListDrawable();
button1bg.addState(new int[] {android.R.attr.state_pressed}, drawable);
button1bg.addState(new int[] {}, drawable2);
button1bg.setExitFadeDuration(250);
button.setBackgroundDrawable(button1bg);
}
示例4: onBindHeaderColumnViewHolder
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
@Override
public void onBindHeaderColumnViewHolder(@NonNull ViewHolderImpl viewHolder, int column) {
TestHeaderColumnViewHolder vh = (TestHeaderColumnViewHolder) viewHolder;
vh.tvText.setText(mTableDataSource.getColumnHeaderData(column)); // skip left top header
int color = COLORS[column % COLORS.length];
GradientDrawable gd = new GradientDrawable(
mIsRtl ? GradientDrawable.Orientation.RIGHT_LEFT : GradientDrawable.Orientation.LEFT_RIGHT,
new int[]{ColorUtils.setAlphaComponent(color, 50), 0x00000000});
gd.setCornerRadius(0f);
vh.vGradient.setBackground(gd);
vh.vLine.setBackgroundColor(color);
}
示例5: initBackGround
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 设置圆角背景
*/
private void initBackGround(){
int fillColor = getResources().getColor(R.color.colorPrimary);
GradientDrawable gd = new GradientDrawable();//创建drawable
gd.setColor(fillColor);
//圆角半径等于高度的一半,合成之后是一个完整的圆
gd.setCornerRadius(allHeight/2f);
gd.getPadding(new Rect(0,0,0,0));
setBackground(gd);
}
示例6: getBadgeDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* @param context to fetch color
* @return return the background drawable
*/
private GradientDrawable getBadgeDrawable(Context context) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadius(context.getResources().getDimensionPixelSize(R.dimen.badge_corner_radius));
shape.setColor(getBackgroundColor(context));
shape.setStroke(getBorderWidth(), getBorderColor(context));
return shape;
}
示例7: 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;
}
示例8: addMenuView
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void addMenuView(Context context, ImageView iv, TextView tv, boolean show) {
//SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
//int cColor = themePrefs.getInt("chatsHeaderTabCounterColor", 0xffffffff);
//int bgColor = themePrefs.getInt("chatsHeaderTabCounterBGColor", 0xffff0000);
iv.setScaleType(ImageView.ScaleType.CENTER);
//int size = themePrefs.getInt("chatsHeaderTabCounterSize", 11);
//tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size);
tv.setGravity(Gravity.RIGHT);
//tv.setTextColor(cColor);
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadius(AndroidUtilities.dp(32));
//shape.setColor(bgColor);
tv.setBackgroundDrawable(shape);
//tv.setPadding(AndroidUtilities.dp(size > 10 ? size - 7 : 4), 0, AndroidUtilities.dp(size > 10 ? size - 7 : 4), 0);
RelativeLayout layout = new RelativeLayout(context);
layout.addView(iv, LayoutHelper.createRelative(50, LayoutHelper.MATCH_PARENT));
layout.addView(tv, LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 10, 5, 0, RelativeLayout.ALIGN_PARENT_RIGHT));
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
tv.setLayoutParams(params);
if (show) {
menu.addView(layout, LayoutHelper.createLinear(50, LayoutHelper.MATCH_PARENT, 0));
}
// MenuCount(notifsCounter);
}
示例9: CodeSpan
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public CodeSpan(int color, int textColor, float radius) {
this.radius = radius;
this.textColor = textColor;
GradientDrawable d = new GradientDrawable();
d.setColor(color);
d.setCornerRadius(radius);
drawable = d;
}
示例10: 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);
}
示例11: createButtonBackgroundDrawableBase
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private static Drawable createButtonBackgroundDrawableBase(int color, int cornerRadius) {
GradientDrawable d = new GradientDrawable();
d.setShape(GradientDrawable.RECTANGLE);
d.setCornerRadius(cornerRadius);
d.setColor(color);
return d;
}
示例12: createRoundedBackground
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public static Drawable createRoundedBackground(Context context) {
int width = dpToPx(context, 2);
int color = fetchAccentColor(context);
GradientDrawable background = new GradientDrawable();
background.setStroke(width, color);
background.setCornerRadius(dpToPx(context, 4));
return background;
}
示例13: AvatarView
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public AvatarView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.view_avatar, this);
imgAvatar = (DynamicRoundedImageView) findViewById(R.id.round_img_avatar);
textAvatar = (FontTextView) findViewById(R.id.text_avatar_name);
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.AvatarView);
int cornerRadius = styledAttrs.getDimensionPixelSize(R.styleable.AvatarView_avCornerRadius, 0);
int bgColor = styledAttrs.getColor(R.styleable.AvatarView_avBgTextColor, Color.parseColor("#964357"));
int textColor = styledAttrs.getColor(R.styleable.AvatarView_avTextColor, Color.parseColor("#FFFFFF"));
float textSize = styledAttrs.getDimension(R.styleable.AvatarView_avTextSize, 24f);
String font = styledAttrs.getString(R.styleable.AvatarView_avFont);
styledAttrs.recycle();
//setting Img corner radius
imgAvatar.setCornerRadius((float) cornerRadius);
//setting bg color and corner radius
GradientDrawable drawable = (GradientDrawable) textAvatar.getBackground();
drawable.setCornerRadius(cornerRadius);
drawable.setColor(bgColor);
textAvatar.invalidate();
//text color and size
textAvatar.setTextColor(textColor);
textAvatar.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
//text font
textAvatar.setFont(font);
}
示例14: setMenuBackground
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 设置菜单背景,如果要显示阴影,需在onLayout之前调用
*/
private void setMenuBackground(){
GradientDrawable gd = new GradientDrawable();
gd.setColor(menuBackColor);
gd.setStroke((int)menuStrokeSize, menuStrokeColor);
gd.setCornerRadius(menuCornerRadius);
setBackground(gd);
}
示例15: initializeColorSeekBar
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void initializeColorSeekBar(Palette palette) {
int defaultColor = 0x000000;
int[] colors = {
palette.getDominantColor(defaultColor),
palette.getVibrantColor(defaultColor),
palette.getMutedColor(defaultColor)};
int px = ivPreview.getHeight() - (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
sbColor = new ColorSeekBar(PreviewActivity.this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, px, 0, 0);
sbColor.setLayoutParams(params);
sbColor.setColorSeeds(colors);
sbColor.setBackground(ContextCompat.getDrawable(PreviewActivity.this, R.drawable.transparent));
sbColor.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() {
@Override
public void onColorChangeListener(int colorBarPosition, int alphaBarPosition, int color) {
presenter.setColor(color);
}
});
px = ivPreview.getHeight() - (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics());
int h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
vSeekBarBacking = new View(PreviewActivity.this);
params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, h);
params.setMargins(0, px, 0, 0);
vSeekBarBacking.setLayoutParams(params);
GradientDrawable gradient = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
gradient.setCornerRadius(0f);
vSeekBarBacking.setBackground(gradient);
rlRoot.addView(vSeekBarBacking);
rlRoot.addView(sbColor);
}