Example usage for android.graphics.drawable GradientDrawable setShape

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

Introduction

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

Prototype

public void setShape(@Shape int shape) 

Source Link

Document

Sets the type of shape used to draw the gradient.

Note: changing this property will affect all instances of a drawable loaded from a resource.

Usage

From source file:io.imoji.sdk.editor.fragment.TagImojiFragment.java

public Drawable createTagDrawable() {

    GradientDrawable d = new GradientDrawable();
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.colorAccent });
    final int accentColor = a.getColor(0, Color.WHITE);
    a.recycle();//from   w  w w. ja va2 s .  com
    d.setColor(0xB3FFFFFF & accentColor);
    d.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d.setShape(GradientDrawable.RECTANGLE);

    GradientDrawable d1 = new GradientDrawable();
    d1.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d1.setStroke((int) getResources().getDimension(R.dimen.dim_0_5dp), 0x66FFFFFF & Color.BLACK);

    GradientDrawable d2 = new GradientDrawable();
    d2.setStroke((int) getResources().getDimension(R.dimen.dim_1dp), accentColor);
    d2.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));

    LayerDrawable layer = new LayerDrawable(new Drawable[] { d, d2, d1 });

    int halfDp = (int) getResources().getDimension(R.dimen.dim_0_5dp);
    int oneDp = (int) getResources().getDimension(R.dimen.dim_1dp);
    int oneAndHalf = halfDp + oneDp;

    layer.setLayerInset(2, 0, 0, 0, 0);
    layer.setLayerInset(1, halfDp, halfDp, halfDp, halfDp);
    layer.setLayerInset(0, oneAndHalf, oneAndHalf, oneAndHalf, oneAndHalf);

    return layer;
}

From source file:am.widget.basetabstrip.BaseTabStrip.java

/**
 * ?Tag/* ww w.j av a 2s .c om*/
 *
 * @return Tag
 */
@SuppressWarnings("unused")
protected Drawable getDefaultTagBackground() {
    final float density = getResources().getDisplayMetrics().density;
    final GradientDrawable mBackground = new GradientDrawable();
    mBackground.setShape(GradientDrawable.RECTANGLE);
    mBackground.setColor(0xffff4444);
    mBackground.setCornerRadius(100000 * density);
    mBackground.setSize((int) (10 * density), (int) (10 * density));
    return mBackground;
}