// Initialize some new ColorDrawable objects
android.graphics.drawable.ColorDrawable leftBorder = new android.graphics.drawable.ColorDrawable(Color.RED);
android.graphics.drawable.ColorDrawable topBorder = new android.graphics.drawable.ColorDrawable(Color.GREEN);
android.graphics.drawable.ColorDrawable rightBorder = new android.graphics.drawable.ColorDrawable(Color.BLUE);
android.graphics.drawable.ColorDrawable bottomBorder = new android.graphics.drawable.ColorDrawable(Color.YELLOW);
android.graphics.drawable.ColorDrawable background = new android.graphics.drawable.ColorDrawable(Color.WHITE);
// Initialize an array of Drawable objects
android.graphics.drawable.Drawable[] layers = new android.graphics.drawable.Drawable[]{
leftBorder, // Red color
topBorder, // Green color
rightBorder, // Blue color
bottomBorder, // Yellow color
background // White background
};
// Initialize a new LayerDrawable
android.graphics.drawable.LayerDrawable layerDrawable = new android.graphics.drawable.LayerDrawable(layers);
// Red layer padding, draw left border
layerDrawable.setLayerInset(0,0,0,15,0);
// Green layer padding, draw top border
layerDrawable.setLayerInset(1,15,0,0,15);
// Blue layer padding, draw right border
layerDrawable.setLayerInset(2,15,15,0,0);
// Yellow layer padding, draw bottom border
layerDrawable.setLayerInset(3,15,15,15,0);
// White layer, draw the background
layerDrawable.setLayerInset(4,15,15,15,15);
textview1.setBackground(layerDrawable);
textview1.setPadding(25,25,25,25);
Komentar