android.graphics.drawable.GradientDrawable#setCornerRadius()源码实例Demo

下面列出了android.graphics.drawable.GradientDrawable#setCornerRadius() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sa-sdk-android   文件: DebugModeSelectDialog.java
@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);
    }
}
 
源代码2 项目: FlycoPageIndicator   文件: RoundCornerIndicaor.java
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);
    }
}
 
源代码3 项目: Musicoco   文件: FeedBackActivity.java
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);

}
 
源代码4 项目: PkRequestManager   文件: QuickScroll.java
/**
 * 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);
}
 
源代码5 项目: coloring   文件: ColoringActivity.java
/**
 * 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);
    }
}
 
源代码6 项目: SegmentedButton   文件: SegmentedButtonGroup.java
/**
 * 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);
    }
}
 
源代码7 项目: RecordVideo   文件: CornerUtils.java
public static Drawable cornerDrawable(final int bgColor, float cornerradius) {
    final GradientDrawable bg = new GradientDrawable();
    bg.setCornerRadius(cornerradius);
    bg.setColor(bgColor);

    return bg;
}
 
源代码8 项目: SegmentedButton   文件: SegmentedButtonGroup.java
/**
 * 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();
}
 
源代码9 项目: RoundButton   文件: RoundButtonHelper.java
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;
}
 
源代码10 项目: ToggleButtonGroup   文件: LabelToggle.java
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);
}
 
源代码11 项目: FlycoPageIndicator   文件: FlycoPageIndicaor.java
private GradientDrawable getDrawable(int color, float raduis) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setCornerRadius(raduis);
    drawable.setStroke(strokeWidth, strokeColor);
    drawable.setColor(color);

    return drawable;
}
 
源代码12 项目: SmartOrnament   文件: CircularProgressButton.java
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;
}
 
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;
}
 
源代码14 项目: RecyclerViewBanner   文件: RecyclerViewBanner.java
/**
 * 默认指示器是一系列直径为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;
}
 
源代码15 项目: Markdown   文件: CodeSpan.java
public CodeSpan(int backgroundColor, int textColor) {
    GradientDrawable d = new GradientDrawable();
    d.setColor(backgroundColor);
    d.setCornerRadius(RADIUS);
    mBackground = d;

    mTextColor = textColor;
}
 
源代码16 项目: mvvm-template   文件: CodeSpan.java
public CodeSpan(int color) {
    GradientDrawable d = new GradientDrawable();
    d.setColor(color);
    d.setCornerRadius(radius);
    drawable = d;
}
 
源代码17 项目: YImagePicker   文件: PCornerUtils.java
public static Drawable cornerDrawable(final int bgColor, float cornerradius) {
    final GradientDrawable bg = new GradientDrawable();
    bg.setCornerRadius(cornerradius);
    bg.setColor(bgColor);
    return bg;
}
 
源代码18 项目: DevUtils   文件: IToastImpl.java
/**
 * 获取一个新的 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;
}
 
源代码19 项目: TwistyTimer   文件: ThemeUtils.java
/**
 * 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;
}
 
源代码20 项目: SimpleProject   文件: ViewBgUtil.java
/**
 * 获取构造的纯色背景 -> 具有相同圆角的场景
 * @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;
}