Java Code Examples for android.graphics.drawable.GradientDrawable#setCornerRadii()
The following examples show how to use
android.graphics.drawable.GradientDrawable#setCornerRadii() .
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: RxTextRoundProgressBar.java From RxTools-master with Apache License 2.0 | 6 votes |
@Override protected void drawProgress(LinearLayout layoutProgress, float max, float progress, float totalWidth, int radius, int padding, int colorProgress, boolean isReverse) { GradientDrawable backgroundDrawable = createGradientDrawable(colorProgress); int newRadius = radius - (padding / 2); backgroundDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius}); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { layoutProgress.setBackground(backgroundDrawable); } else { layoutProgress.setBackgroundDrawable(backgroundDrawable); } float ratio = max / progress; int progressWidth = (int) ((totalWidth - (padding * 2)) / ratio); ViewGroup.LayoutParams progressParams = layoutProgress.getLayoutParams(); progressParams.width = progressWidth; layoutProgress.setLayoutParams(progressParams); }
Example 2
Source File: RoundCornerProgressBar.java From RoundCornerProgressBar with Apache License 2.0 | 6 votes |
@Override protected void drawProgress(@NonNull LinearLayout layoutProgress, @NonNull GradientDrawable progressDrawable, float max, float progress, float totalWidth, int radius, int padding, boolean isReverse) { int newRadius = radius - (padding / 2); progressDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius}); layoutProgress.setBackground(progressDrawable); float ratio = max / progress; int progressWidth = (int) ((totalWidth - (padding * 2)) / ratio); ViewGroup.MarginLayoutParams progressParams = (ViewGroup.MarginLayoutParams) layoutProgress.getLayoutParams(); progressParams.width = progressWidth; if (padding + (progressWidth / 2) < radius) { int margin = Math.max(radius - padding, 0) - (progressWidth / 2); progressParams.topMargin = margin; progressParams.bottomMargin = margin; } else { progressParams.topMargin = 0; progressParams.bottomMargin = 0; } layoutProgress.setLayoutParams(progressParams); }
Example 3
Source File: TextRoundCornerProgressBar.java From UltimateAndroid with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @SuppressLint("NewApi") public void setProgressColor(int color) { progressColor = color; int radius = this.radius - (padding / 2); GradientDrawable gradient = new GradientDrawable(); gradient.setShape(GradientDrawable.RECTANGLE); gradient.setColor(progressColor); gradient.setCornerRadii(new float [] { radius, radius, radius, radius, radius, radius, radius, radius}); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { layoutProgress.setBackground(gradient); } else { layoutProgress.setBackgroundDrawable(gradient); } if(!isProgressBarCreated) { isProgressColorSetBeforeDraw = true; } }
Example 4
Source File: BootstrapDrawableFactory.java From Android-Bootstrap with MIT License | 6 votes |
static Drawable bootstrapThumbnail(Context context, BootstrapBrand bootstrapBrand, @ColorInt int outerBorderWidth, @ColorInt int bg, boolean rounded) { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setColor(bg); drawable.setStroke(outerBorderWidth, bootstrapBrand.defaultEdge(context)); float r = DimenUtils.pixelsFromDpResource(context, R.dimen.bthumbnail_rounded_corner); if (rounded) { drawable.setCornerRadii(new float[]{r, r, r, r, r, r, r, r}); } return drawable; }
Example 5
Source File: ScrollSlidingTextTabStrip.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public ScrollSlidingTextTabStrip(Context context) { super(context); selectorDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null); float rad = AndroidUtilities.dpf2(3); selectorDrawable.setCornerRadii(new float[]{rad, rad, rad, rad, 0, 0, 0, 0}); selectorDrawable.setColor(Theme.getColor(tabLineColorKey)); setFillViewport(true); setWillNotDraw(false); setHorizontalScrollBarEnabled(false); tabsContainer = new LinearLayout(context) { @Override public void setAlpha(float alpha) { super.setAlpha(alpha); ScrollSlidingTextTabStrip.this.invalidate(); } }; tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setPadding(AndroidUtilities.dp(7), 0, AndroidUtilities.dp(7), 0); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); addView(tabsContainer); }
Example 6
Source File: RxBaseRoundProgressBar.java From RxTools-master with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") private void drawBackgroundProgress() { GradientDrawable backgroundDrawable = createGradientDrawable(colorBackground); int newRadius = radius - (padding / 2); backgroundDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius}); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { layoutBackground.setBackground(backgroundDrawable); } else { layoutBackground.setBackgroundDrawable(backgroundDrawable); } }
Example 7
Source File: PCornerUtils.java From YImagePicker with Apache License 2.0 | 5 votes |
public static Drawable cornerDrawable(final int bgColor, float[] cornerradius, int borderwidth, int bordercolor) { final GradientDrawable bg = new GradientDrawable(); bg.setCornerRadii(cornerradius); bg.setStroke(borderwidth, bordercolor); bg.setColor(bgColor); return bg; }
Example 8
Source File: TextRoundCornerProgressBar.java From RoundCornerProgressBar with Apache License 2.0 | 5 votes |
@Override protected void drawProgress(@NonNull LinearLayout layoutProgress, @NonNull GradientDrawable progressDrawable, float max, float progress, float totalWidth, int radius, int padding, boolean isReverse) { int newRadius = radius - (padding / 2); progressDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius}); layoutProgress.setBackground(progressDrawable); float ratio = max / progress; int progressWidth = (int) ((totalWidth - (padding * 2)) / ratio); ViewGroup.MarginLayoutParams progressParams = (ViewGroup.MarginLayoutParams) layoutProgress.getLayoutParams(); if (padding + (progressWidth / 2) < radius) { int margin = Math.max(radius - padding, 0) - (progressWidth / 2); progressParams.topMargin = margin; progressParams.bottomMargin = margin; } else { progressParams.topMargin = 0; progressParams.bottomMargin = 0; } progressParams.width = progressWidth; layoutProgress.setLayoutParams(progressParams); }
Example 9
Source File: ApplicationView.java From LauncherTV with Apache License 2.0 | 5 votes |
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); }
Example 10
Source File: DrawableUtil.java From UtilsLib with MIT License | 5 votes |
/** * 使用代码创建指定圆角大小的矩形shape形状 * * @param rgb 形状颜色 * @param topLeftRadius 左上角的圆角尺寸 * @param topRightRadius 右上角的圆角尺寸 * @param bottomLeftRadius 左下角的圆角尺寸 * @param bottomRightRadius 右下角的圆角尺寸 * @return 指定形状的Drawable对象 */ public static GradientDrawable createRectangleDrawable(int rgb, float topLeftRadius, float topRightRadius, float bottomLeftRadius, float bottomRightRadius) { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE);//设置矩形 //创建圆角 float[] radius = { topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius}; drawable.setCornerRadii(radius); drawable.setColor(rgb); return drawable; }
Example 11
Source File: NoteEditDialog.java From CrazyDaily with Apache License 2.0 | 5 votes |
private void initView() { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(Color.WHITE); float radius = ScreenUtil.dp2px(mActivity, 15); float[] radii = new float[]{radius, radius, radius, radius, 0, 0, 0, 0}; drawable.setCornerRadii(radii); GradientDrawable itemDrawable = new GradientDrawable(); itemDrawable.setColor(Color.parseColor("#F2F2F2")); itemDrawable.setCornerRadius(ScreenUtil.dp2px(mActivity, 35)); mEdit.setBackground(itemDrawable); mDelete.setBackground(itemDrawable); mWrap.setBackground(drawable); mEdit.setOnClickListener(v -> { if (mOnItemClickListener != null) { mOnItemClickListener.onEdit(); } }); mDelete.setOnClickListener(v -> { if (mOnItemClickListener != null) { mOnItemClickListener.onDelete(); } }); mCancel.setOnClickListener(v -> { if (mOnItemClickListener != null) { mOnItemClickListener.onCancel(); } }); }
Example 12
Source File: CornerUtils.java From FlycoDialog_Master with MIT License | 5 votes |
public static Drawable cornerDrawable(final int bgColor, float[] cornerradius) { final GradientDrawable bg = new GradientDrawable(); bg.setCornerRadii(cornerradius); bg.setColor(bgColor); return bg; }
Example 13
Source File: FlatTabGroup.java From support with Apache License 2.0 | 5 votes |
private Drawable generateDrawable(int position, int color) { float[] radius; if (position == 0) { radius = new float[]{ mRadius, mRadius, 0, 0, 0, 0, mRadius, mRadius }; } else if (position == getChildCount() - 1) { radius = new float[]{ 0, 0, mRadius, mRadius, mRadius, mRadius, 0, 0 }; } else { radius = new float[]{ 0, 0, 0, 0, 0, 0, 0, 0 }; } GradientDrawable shape = new GradientDrawable(); shape.setCornerRadii(radius); shape.setColor(color); shape.setStroke(mStroke, mHighlightColor); return shape; }
Example 14
Source File: GosDeploy.java From Gizwits-SmartBuld_Android with MIT License | 5 votes |
/** * 设置Button背景颜色 * * @return */ public static Drawable setButtonBackgroundColor() { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setCornerRadii(new float[] { 50, 50, 50, 50, 50, 50, 50, 50 }); String ButtonColor_FromMap = infoMap.get(ButtonColor_Key).toString(); if (!TextUtils.isEmpty(ButtonColor_FromMap)) { drawable.setColor(Color.parseColor("#" + ButtonColor_FromMap)); } else { drawable.setColor(context.getResources().getColor(R.color.yellow)); } return drawable; }
Example 15
Source File: BaseRoundCornerProgressBar.java From RoundCornerProgressBar with Apache License 2.0 | 4 votes |
private void drawBackgroundProgress() { GradientDrawable backgroundDrawable = createGradientDrawable(backgroundColor); int newRadius = radius - (padding / 2); backgroundDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius}); layoutBackground.setBackground(backgroundDrawable); }
Example 16
Source File: EditFileStoryActivity.java From talk-android with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_file_story); ButterKnife.inject(this); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(""); file = GsonProvider.getGson().fromJson(story.getData(), File.class); originFileKey = file.getFileKey(); originText = file.getText() == null ? "" : file.getText(); originFileName = file.getFileName(); etTitle.setText(originFileName); etText.setText(originText); etTitle.setSelection(file.getFileName().length()); if (BizLogic.isImg(file)) { tvFileScheme.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); vUpload.setVisibility(View.VISIBLE); MainApp.IMAGE_LOADER.displayImage(file.getDownloadUrl(), imageView, ImageLoaderConfig.EMPTY_OPTIONS); } else { tvFileScheme.setVisibility(View.VISIBLE); imageView.setVisibility(View.GONE); vUpload.setVisibility(View.GONE); GradientDrawable drawable = new GradientDrawable(); final float radius = MainApp.CONTEXT.getResources().getDimension(R.dimen.story_chat_file_radius); drawable.setCornerRadii(new float[]{radius, radius, radius, radius, radius, radius, radius, radius}); drawable.setColor(Color.parseColor(file.getSchemeColor(file.getFileType()))); tvFileScheme.setBackgroundDrawable(drawable); tvFileScheme.setText(file.getFileType()); } new Handler().postDelayed(new Runnable() { @Override public void run() { tilTitle.setVisibility(View.VISIBLE); tilText.setVisibility(View.VISIBLE); layoutImage.setVisibility(View.VISIBLE); } }, 200); vUpload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TransactionUtil.goToForResult(EditFileStoryActivity.this, SelectImageActivity.class, SelectImageActivity.SELECT_IMAGES); } }); etTitle.addTextChangedListener(watcher); etText.addTextChangedListener(watcher); }
Example 17
Source File: PopupList.java From a with GNU General Public License v3.0 | 4 votes |
private void refreshBackgroundOrRadiusStateList() { // left GradientDrawable leftItemPressedDrawable = new GradientDrawable(); leftItemPressedDrawable.setColor(mPressedBackgroundColor); leftItemPressedDrawable.setCornerRadii(new float[]{ mBackgroundCornerRadius, mBackgroundCornerRadius, 0, 0, 0, 0, mBackgroundCornerRadius, mBackgroundCornerRadius}); GradientDrawable leftItemNormalDrawable = new GradientDrawable(); leftItemNormalDrawable.setColor(Color.TRANSPARENT); leftItemNormalDrawable.setCornerRadii(new float[]{ mBackgroundCornerRadius, mBackgroundCornerRadius, 0, 0, 0, 0, mBackgroundCornerRadius, mBackgroundCornerRadius}); mLeftItemBackground = new StateListDrawable(); mLeftItemBackground.addState(new int[]{android.R.attr.state_pressed}, leftItemPressedDrawable); mLeftItemBackground.addState(new int[]{}, leftItemNormalDrawable); // right GradientDrawable rightItemPressedDrawable = new GradientDrawable(); rightItemPressedDrawable.setColor(mPressedBackgroundColor); rightItemPressedDrawable.setCornerRadii(new float[]{ 0, 0, mBackgroundCornerRadius, mBackgroundCornerRadius, mBackgroundCornerRadius, mBackgroundCornerRadius, 0, 0}); GradientDrawable rightItemNormalDrawable = new GradientDrawable(); rightItemNormalDrawable.setColor(Color.TRANSPARENT); rightItemNormalDrawable.setCornerRadii(new float[]{ 0, 0, mBackgroundCornerRadius, mBackgroundCornerRadius, mBackgroundCornerRadius, mBackgroundCornerRadius, 0, 0}); mRightItemBackground = new StateListDrawable(); mRightItemBackground.addState(new int[]{android.R.attr.state_pressed}, rightItemPressedDrawable); mRightItemBackground.addState(new int[]{}, rightItemNormalDrawable); // corner GradientDrawable cornerItemPressedDrawable = new GradientDrawable(); cornerItemPressedDrawable.setColor(mPressedBackgroundColor); cornerItemPressedDrawable.setCornerRadius(mBackgroundCornerRadius); GradientDrawable cornerItemNormalDrawable = new GradientDrawable(); cornerItemNormalDrawable.setColor(Color.TRANSPARENT); cornerItemNormalDrawable.setCornerRadius(mBackgroundCornerRadius); mCornerItemBackground = new StateListDrawable(); mCornerItemBackground.addState(new int[]{android.R.attr.state_pressed}, cornerItemPressedDrawable); mCornerItemBackground.addState(new int[]{}, cornerItemNormalDrawable); mCornerBackground = new GradientDrawable(); mCornerBackground.setColor(mNormalBackgroundColor); mCornerBackground.setCornerRadius(mBackgroundCornerRadius); }
Example 18
Source File: SuperDialog.java From SuperDialog with Apache License 2.0 | 4 votes |
private GradientDrawable getDialogBackground(float[] corner) { GradientDrawable gd = new GradientDrawable(); gd.setCornerRadii(corner); gd.setColor(dialogBackground); return gd; }
Example 19
Source File: IconRoundCornerProgressBar.java From RoundCornerProgressBar with Apache License 2.0 | 4 votes |
private void drawIconBackgroundColor() { GradientDrawable iconBackgroundDrawable = createGradientDrawable(colorIconBackground); int radius = getRadius() - (getPadding() / 2); iconBackgroundDrawable.setCornerRadii(new float[]{radius, radius, 0, 0, 0, 0, radius, radius}); ivProgressIcon.setBackground(iconBackgroundDrawable); }
Example 20
Source File: X8TabHost.java From FimiX8-RE with MIT License | 4 votes |
private void sove() { GradientDrawable dd = new GradientDrawable(); dd.setCornerRadii(new float[]{(float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius}); dd.setStroke(this.lineStroke, this.lineColor); if (VERSION.SDK_INT >= 16) { setBackground(dd); } else { setBackgroundDrawable(dd); } removeAllViews(); if (this.curIndex >= this.textArr.length || this.curIndex < 0) { this.curIndex = 0; } for (int i = 0; i < this.textArr.length; i++) { TextView tv = new TextView(getContext()); LayoutParams params = new LayoutParams(0, -1); if (i > 0) { params.leftMargin = this.space; } GradientDrawable d = getFitGradientDrawable(i); if (this.curIndex == i) { tv.setTextColor(this.selectTextColor); d.setColor(this.selectTabBg); } else { tv.setTextColor(this.unSelectTextColor); d.setColor(this.unSelectTabBg); } tv.setText(this.textArr[i]); tv.setGravity(17); tv.setTextSize(0, this.textSize); if (VERSION.SDK_INT >= 16) { tv.setBackground(d); } else { tv.setBackgroundDrawable(d); } params.weight = 1.0f; tv.setLayoutParams(params); tv.setTag(Integer.valueOf(i)); tv.setOnClickListener(this); addView(tv); } }