Example usage for android.graphics.drawable GradientDrawable GradientDrawable

List of usage examples for android.graphics.drawable GradientDrawable GradientDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable GradientDrawable GradientDrawable.

Prototype

public GradientDrawable() 

Source Link

Usage

From source file:Main.java

public static GradientDrawable getShape(float radius, int color) {
    GradientDrawable gd = new GradientDrawable();
    //        gd.setShape(GradientDrawable.OVAL); The larger the radius, the more round the radius
    gd.setCornerRadius(radius);//www .  j  a  v  a 2 s.c o  m
    gd.setColor(color);
    return gd;
}

From source file:Main.java

public static Drawable createRoundRectShape(int corner, int color) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setCornerRadius(corner);//from  w  w w.j a va 2s .  c o m
    drawable.setColor(color);
    return drawable;
}

From source file:Main.java

public static GradientDrawable getDrawable(int radius, int fillColor, int width, int strokeColor) {
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setCornerRadius(radius);
    gradientDrawable.setColor(fillColor);
    gradientDrawable.setStroke(width, strokeColor);
    return gradientDrawable;
}

From source file:Main.java

public static void makeRoundCorner(View v, int color, int radius) {
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setColor(color);// www. ja va 2 s  .c o  m
    gradientDrawable.setCornerRadius(radius);
    if (Build.VERSION.SDK_INT < 16)
        v.setBackgroundDrawable(gradientDrawable);
    else
        v.setBackground(gradientDrawable);
}

From source file:Main.java

public static GradientDrawable createBackgroundRandom() {
    Random rnd = new Random();
    int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
    GradientDrawable gd = new GradientDrawable();
    gd.setColor(color);//ww  w .  j  av a2 s . co  m
    gd.setCornerRadius(5);
    gd.setAlpha(90);
    return gd;
}

From source file:Main.java

/**
 *
 * @param radius/*w  ww  . ja v  a 2s  .  c  o  m*/
 * @return
 * @deprecated Change to use ViewUtils.
 */
@Deprecated
public static GradientDrawable getShapeDrawable(float radius) {
    GradientDrawable shape = new GradientDrawable();
    shape.setColor(Color.TRANSPARENT);
    shape.setCornerRadius(radius);
    return shape;
}

From source file:Main.java

public static Drawable createRandomColorShapeDrawable() {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    drawable.setCornerRadius(5);/*from  w w  w  .ja  v a2 s  .c  o m*/
    drawable.setColor(createRandomColor());
    return drawable;
}

From source file:Main.java

public static Drawable createDrawableBackground(int color, int cornerRadius, boolean hasBorder,
        int borderThickness, int borderColor) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    if (hasBorder)
        drawable.setStroke(borderThickness, borderColor);
    drawable.setCornerRadius(cornerRadius);
    drawable.setColor(color);/*from   w  w  w. jav a2s  . co m*/
    return drawable;
}

From source file:Main.java

/**
 * Set the background of a {@link android.view.View} to the specified color, with a darker version of the
 * color as a border./* ww  w  . j a va2 s.  c o  m*/
 */
public static void setViewBackground(View view, int color) {
    Resources r = view.getResources();

    Drawable currentDrawable = view.getBackground();
    GradientDrawable backgroundDrawable;
    if (currentDrawable != null && currentDrawable instanceof GradientDrawable) {
        // Reuse drawable
        backgroundDrawable = (GradientDrawable) currentDrawable;
    } else {
        backgroundDrawable = new GradientDrawable();
    }

    int darkenedColor = darkenColor(color);

    backgroundDrawable.setColor(color);
    backgroundDrawable.setStroke(
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()),
            darkenedColor);

    view.setBackgroundDrawable(backgroundDrawable);
}

From source file:Main.java

public static Drawable cornerDrawable(final int bgColor, float cornerradius) {
    final GradientDrawable bg = new GradientDrawable();
    bg.setCornerRadius(cornerradius);/*from  ww w  .  j  a  v a  2s  . c o m*/
    bg.setColor(bgColor);

    return bg;
}