Java tutorial
//package com.java2s; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.view.View; public class Main { public static void applyBorderDrawableToView(View v, int backgroundColor, int borderColor, int cornerRadius, int borderThickness) { Drawable drawable; drawable = createDrawableBackground(backgroundColor, cornerRadius, true, borderThickness, borderColor); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { v.setBackgroundDrawable(drawable); } else { v.setBackground(drawable); } } 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); return drawable; } }