Java Code Examples for android.graphics.drawable.GradientDrawable#setCornerRadius()
The following examples show how to use
android.graphics.drawable.GradientDrawable#setCornerRadius() .
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: DebugModeSelectDialog.java From sa-sdk-android with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.sensors_analytics_debug_mode_dialog_content); initView(); Window window = getWindow(); if (window != null) { WindowManager.LayoutParams p = window.getAttributes(); p.width = dip2px(getContext(), 270); p.height = dip2px(getContext(), 240); window.setAttributes(p); //设置弹框圆角 GradientDrawable bg = new GradientDrawable(); bg.setShape(GradientDrawable.RECTANGLE); bg.setColor(Color.WHITE); bg.setCornerRadius(dip2px(getContext(), 7)); window.setBackgroundDrawable(bg); } }
Example 2
Source File: ColoringActivity.java From coloring with GNU General Public License v3.0 | 6 votes |
/** * Updates the color of the color picker selected button with the actual color (a gradient from it). */ private void updateColorOfColorPickerButton() { View view = findViewById(R.id.colorPickerButton); // takes the actually selected color int color = Library.getInstance().getSelectedColor(); int[] gradientColors = ColoringUtils.colorSelectionButtonBackgroundGradient(color); if (Build.VERSION.SDK_INT < 16) { GradientDrawable newGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, gradientColors); newGradientDrawable.setStroke(1, Color.parseColor("#bbbbbb")); newGradientDrawable.setCornerRadius(ColoringActivity.this.getResources().getDimension(R.dimen.color_selection_button_corner_radius)); //noinspection deprecation view.setBackgroundDrawable(newGradientDrawable); } else { GradientDrawable drawable = (GradientDrawable) view.getBackground(); drawable.mutate(); drawable.setColors(gradientColors); } }
Example 3
Source File: RoundCornerIndicaor.java From FlycoPageIndicator with MIT License | 6 votes |
private void drawUnselect(Canvas canvas, int count, int verticalOffset, int horizontalOffset) { for (int i = 0; i < count; i++) { Rect rect = unselectRects.get(i); rect.left = horizontalOffset + (indicatorWidth + indicatorGap) * i; rect.top = verticalOffset; rect.right = rect.left + indicatorWidth; rect.bottom = rect.top + indicatorHeight; GradientDrawable unselectDrawable = unselectDrawables.get(i); unselectDrawable.setCornerRadius(cornerRadius); unselectDrawable.setColor(unselectColor); unselectDrawable.setStroke(strokeWidth, strokeColor); unselectDrawable.setBounds(rect); unselectDrawable.draw(canvas); } }
Example 4
Source File: FeedBackActivity.java From Musicoco with Apache License 2.0 | 6 votes |
private void initInputBg(int accentC, int vicBC) { GradientDrawable gd = new GradientDrawable(); gd.setColor(vicBC); gd.setCornerRadius(10); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { gd.setStroke(3, new ColorStateList( new int[][]{ {android.R.attr.state_focused}, {}}, new int[]{ accentC, android.support.v4.graphics.ColorUtils.setAlphaComponent(accentC, 200) } )); } else { gd.setStroke(3, accentC); } input.setBackground(gd); }
Example 5
Source File: QuickScroll.java From PkRequestManager with MIT License | 6 votes |
/** * Sets the popup colors, when QuickScroll.TYPE_POPUP is selected as type. * <p/> * * @param backgroundcolor * the background color of the TextView * @param bordercolor * the background color of the border surrounding the TextView * @param textcolor * the color of the text */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public void setPopupColor(final int backgroundcolor, final int bordercolor, final int borderwidthDPI, final int textcolor, float cornerradiusDPI) { final GradientDrawable popupbackground = new GradientDrawable(); popupbackground.setCornerRadius(cornerradiusDPI * getResources().getDisplayMetrics().density); popupbackground.setStroke((int) (borderwidthDPI * getResources().getDisplayMetrics().density), bordercolor); popupbackground.setColor(backgroundcolor); if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) mScrollIndicatorText.setBackgroundDrawable(popupbackground); else mScrollIndicatorText.setBackground(popupbackground); mScrollIndicatorText.setTextColor(textcolor); }
Example 6
Source File: CodeSpan.java From Markdown with MIT License | 5 votes |
public CodeSpan(int backgroundColor, int textColor) { GradientDrawable d = new GradientDrawable(); d.setColor(backgroundColor); d.setCornerRadius(RADIUS); mBackground = d; mTextColor = textColor; }
Example 7
Source File: RecyclerViewBanner.java From RecyclerViewBanner with Apache License 2.0 | 5 votes |
/** * 默认指示器是一系列直径为6dp的小圆点 */ private GradientDrawable generateDefaultDrawable(int color) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setSize(dp2px(6), dp2px(6)); gradientDrawable.setCornerRadius(dp2px(6)); gradientDrawable.setColor(color); return gradientDrawable; }
Example 8
Source File: MobicomMessageTemplateAdapter.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
public GradientDrawable getShape(Context context) { GradientDrawable bgShape = new GradientDrawable(); bgShape.setShape(GradientDrawable.RECTANGLE); bgShape.setColor(Color.parseColor(messageTemplate.getBackGroundColor())); bgShape.setCornerRadius(dpToPixels(context, messageTemplate.getCornerRadius())); bgShape.setStroke(dpToPixels(context, 2), Color.parseColor(messageTemplate.getBorderColor())); return bgShape; }
Example 9
Source File: CircularProgressButton.java From SmartOrnament with Apache License 2.0 | 5 votes |
private StrokeGradientDrawable createDrawable(int color) { GradientDrawable drawable = (GradientDrawable) getResources().getDrawable(R.drawable.cpb_background).mutate(); drawable.setColor(color); drawable.setCornerRadius(mCornerRadius); StrokeGradientDrawable strokeGradientDrawable = new StrokeGradientDrawable(drawable); strokeGradientDrawable.setStrokeColor(color); strokeGradientDrawable.setStrokeWidth(mStrokeWidth); return strokeGradientDrawable; }
Example 10
Source File: FlycoPageIndicaor.java From FlycoPageIndicator with MIT License | 5 votes |
private GradientDrawable getDrawable(int color, float raduis) { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(raduis); drawable.setStroke(strokeWidth, strokeColor); drawable.setColor(color); return drawable; }
Example 11
Source File: LabelToggle.java From ToggleButtonGroup with Apache License 2.0 | 5 votes |
private void initBackground() { GradientDrawable checked = new GradientDrawable(); checked.setColor(mMarkerColor); checked.setCornerRadius(dpToPx(25)); checked.setStroke(1, mMarkerColor); mIvBg.setImageDrawable(checked); GradientDrawable unchecked = new GradientDrawable(); unchecked.setColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); unchecked.setCornerRadius(dpToPx(25)); unchecked.setStroke((int) dpToPx(1), mMarkerColor); mTvText.setBackgroundDrawable(unchecked); }
Example 12
Source File: RoundButtonHelper.java From RoundButton with MIT License | 5 votes |
public static GradientDrawable createDrawable(int color, int cornerColor, int cornerSize, int cornerRadius) { GradientDrawable out = new GradientDrawable(); out.setColor(color); out.setStroke(cornerSize, cornerColor); out.setCornerRadius(cornerRadius); return out; }
Example 13
Source File: SegmentedButtonGroup.java From SegmentedButton with Apache License 2.0 | 5 votes |
/** * Set drawable as divider between buttons with a specified width, corner radius and padding * * If the drawable is null, then the divider will be removed and hidden * * @param drawable divider drawable that will be displayed between buttons * @param width width of the divider drawable, in pixels * @param radius corner radius of the divider drawable to round the corners, in pixels * @param padding space above and below the divider drawable within the button group, in pixels */ public void setDivider(@Nullable Drawable drawable, int width, int radius, int padding) { // Drawable of null indicates that we want to hide dividers if (drawable == null) { dividerLayout.setDividerDrawable(null); dividerLayout.setShowDividers(SHOW_DIVIDER_NONE); return; } // Set the corner radius and size if the drawable is a GradientDrawable // Otherwise just set the divider drawable like normal because we cant set the parameters if (drawable instanceof GradientDrawable) { GradientDrawable gradient = (GradientDrawable)drawable; gradient.setSize(width, 0); gradient.setCornerRadius(radius); dividerLayout.setDividerDrawable(gradient); } else { dividerLayout.setDividerDrawable(drawable); } dividerLayout.setDividerPadding(padding); dividerLayout.setShowDividers(SHOW_DIVIDER_MIDDLE); // Loop through and update the divider width for each of the dummy divider views for (int i = 0; i < dividerLayout.getChildCount(); ++i) { final ButtonActor view = (ButtonActor)dividerLayout.getChildAt(i); view.setDividerWidth(width); } dividerLayout.requestLayout(); }
Example 14
Source File: CornerUtils.java From RecordVideo with Apache License 2.0 | 5 votes |
public static Drawable cornerDrawable(final int bgColor, float cornerradius) { final GradientDrawable bg = new GradientDrawable(); bg.setCornerRadius(cornerradius); bg.setColor(bgColor); return bg; }
Example 15
Source File: SegmentedButtonGroup.java From SegmentedButton with Apache License 2.0 | 5 votes |
/** * Set the border for the perimeter of the button group. * * @param width Width of the border in pixels (default value is 0px or no border) * @param color Color of the border (default color is black) * @param dashWidth Width of the dash for border, in pixels. Value of 0px means solid line (default is 0px) * @param dashGap Width of the gap for border, in pixels. */ public void setBorder(int width, @ColorInt int color, int dashWidth, int dashGap) { borderWidth = width; borderColor = color; borderDashWidth = dashWidth; borderDashGap = dashGap; // Border width of 0 indicates to hide borders if (width > 0) { GradientDrawable borderDrawable = new GradientDrawable(); // Set background color to be transparent so that buttons and everything underneath the border view is // still visible. This was an issue on API 16 Android where it would default to a black background borderDrawable.setColor(Color.TRANSPARENT); // Corner radius is the radius minus half of the border width because the drawable will draw the stroke // from the center, so the actual corner radius is reduced // If the half border width is left out, the border radius does not follow the curve of the background borderDrawable.setCornerRadius(radius - width / 2.0f); borderDrawable.setStroke(width, color, dashWidth, dashGap); borderView.setBackground(borderDrawable); } else { borderView.setBackground(null); } }
Example 16
Source File: PCornerUtils.java From YImagePicker with Apache License 2.0 | 4 votes |
public static Drawable cornerDrawable(final int bgColor, float cornerradius) { final GradientDrawable bg = new GradientDrawable(); bg.setCornerRadius(cornerradius); bg.setColor(bgColor); return bg; }
Example 17
Source File: IToastImpl.java From DevUtils with Apache License 2.0 | 4 votes |
/** * 获取一个新的 View Toast * @param style Toast 样式 {@link IToast.Style} * @param view Toast 显示的 View * @param duration Toast 显示时长 {@link Toast#LENGTH_SHORT}、{@link Toast#LENGTH_LONG} * @return {@link Toast} */ private Toast newToastView(final IToast.Style style, final View view, final int duration) { if (style == null) { return null; } else if (view == null) { // 防止显示的 View 为 null return null; } try { // 关闭旧的 Toast if (mToast != null) { mToast.cancel(); mToast = null; } // 获取背景图片 Drawable backgroundDrawable = style.getBackground(); // 如果等于 null if (backgroundDrawable != null) { // 设置背景 ViewUtils.setBackground(view, backgroundDrawable); } else { if (style.getBackgroundTintColor() != 0) { GradientDrawable drawable = new GradientDrawable(); // 设置背景色 drawable.setColor(style.getBackgroundTintColor()); // 设置圆角大小 drawable.setCornerRadius(style.getCornerRadius()); // 设置背景 ViewUtils.setBackground(view, drawable); } } // 创建 Toast mToast = ToastFactory.create(DevUtils.getContext()); mToast.setView(view); // 设置属性配置 if (style.getGravity() != 0) { // 设置 Toast 的重心、X、Y 轴偏移 mToast.setGravity(style.getGravity(), style.getXOffset(), style.getYOffset()); } // 设置边距 mToast.setMargin(style.getHorizontalMargin(), style.getVerticalMargin()); // 设置显示时间 mToast.setDuration(duration); } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "newToastView"); } return mToast; }
Example 18
Source File: CodeSpan.java From mvvm-template with GNU General Public License v3.0 | 4 votes |
public CodeSpan(int color) { GradientDrawable d = new GradientDrawable(); d.setColor(color); d.setCornerRadius(radius); drawable = d; }
Example 19
Source File: ThemeUtils.java From TwistyTimer with GNU General Public License v3.0 | 3 votes |
/** * Creates and returns a {@link GradientDrawable} shape with custom radius and colors. * @param context Current context * @param backgroundColors 2 or 3 int array with the shape background colors * @param strokeColor Color of the shape stroke * @param cornerRadius Radius of the shape in dp * @param strokeWidth Stroke width in dp * @return A {@link GradientDrawable} with the set arguments */ public static GradientDrawable createSquareDrawable(Context context, int[] backgroundColors, int strokeColor, int cornerRadius, float strokeWidth) { GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, backgroundColors); gradientDrawable.setStroke(ThemeUtils.dpToPix(context, strokeWidth), strokeColor); gradientDrawable.setCornerRadius(ThemeUtils.dpToPix(context, cornerRadius)); return gradientDrawable; }
Example 20
Source File: ViewBgUtil.java From SimpleProject with MIT License | 3 votes |
/** * 获取构造的纯色背景 -> 具有相同圆角的场景 * @param shape 表示背景形状,取值为: * GradientDrawable.RECTANGLE: 表示矩形 * GradientDrawable.OVAL: 表示圆形 * GradientDrawable.LINE: 表示线条 * @param bgColor 背景颜色 * @param borderColor 边框颜色 * @param borderWidth 边框宽度 * @param radius 圆角大小 * @return */ public static Drawable getDrawable(int shape, int bgColor, int borderColor, int borderWidth, int radius) { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(shape); drawable.setColor(bgColor); drawable.setStroke(borderWidth, borderColor); drawable.setCornerRadius(radius); return drawable; }