android layer-list overlap shape item code example

Example: android dynamically create layer-list with item and shape site:stackoverflow.com

GradientDrawable layer1 = new GradientDrawable();
    layer1.setShape(GradientDrawable.OVAL);
    layer1.setSize(33,33);
    layer1.setColor(Color.WHITE);
    layer1.setStroke(4,Color.RED);

    GradientDrawable layer2 = new GradientDrawable();
    layer2.setShape(GradientDrawable.OVAL);
    layer2.setColor(Color.BLUE);

    InsetDrawable insetLayer2 = new InsetDrawable(layer1, 8, 8, 8, 8);

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]
    {insetLayer2,layer2});
    button.setBackground(layerDrawable);

Tags:

Java Example