Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;

public class Main {
    public static LayerDrawable getBorderLayerDrawable(int color, int backgroundColor, int padding, int radius) {
        Drawable[] layers = new Drawable[2];
        layers[0] = getShapeDrawable(color, radius);
        layers[0].setState(new int[] { android.R.attr.state_enabled });
        layers[1] = getShapeDrawable(backgroundColor, radius);
        layers[1].setState(new int[] { android.R.attr.state_enabled });
        LayerDrawable layerDrawable = new LayerDrawable(layers);
        layerDrawable.setLayerInset(1, padding, padding, padding, padding);
        return layerDrawable;
    }

    public static ShapeDrawable getShapeDrawable(int color, int radius) {
        RoundRectShape roundRectShape = new RoundRectShape(
                new float[] { radius, radius, radius, radius, radius, radius, radius, radius }, null, null);
        ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape);
        shapeDrawable.getPaint().setColor(color);
        return shapeDrawable;
    }
}