Created
October 1, 2015 13:56
-
-
Save ptsiogas/e11b29a4324a58cb4d41 to your computer and use it in GitHub Desktop.
Create shadow effect background color programmatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates background color with shadow effect - programmatically | |
* | |
* @param color the background color | |
*/ | |
private LayerDrawable setLayerShadow(String color) { | |
GradientDrawable shadow; | |
int strokeValue = 6; | |
int radiousValue = 2; | |
try{ | |
int[] colors1 = {Color.parseColor(color), Color.parseColor("#FFFFFF")}; | |
shadow = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1); | |
shadow.setCornerRadius(radiousValue); | |
} | |
catch(Exception e){ | |
int[] colors1 = {Color.parseColor("#419ED9"), Color.parseColor("#419ED9")}; | |
shadow = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1); | |
shadow.setCornerRadius(radiousValue); | |
e.printStackTrace(); | |
} | |
int[] colors = {Color.parseColor("#D8D8D8"), Color.parseColor("#E5E3E4")}; | |
GradientDrawable backColor = new GradientDrawable(GradientDrawable.Orientation.BL_TR, colors); | |
backColor.setCornerRadius(radiousValue); | |
backColor.setStroke(strokeValue, Color.parseColor("#D8D8D8")); | |
//finally c.reate a layer list and set them as background. | |
Drawable[] layers = new Drawable[2]; | |
layers[0] = backColor; | |
layers[1] = shadow; | |
LayerDrawable layerList = new LayerDrawable(layers); | |
layerList.setLayerInset(0, 0, 0, 0, 0); | |
layerList.setLayerInset(1, strokeValue, strokeValue, strokeValue, strokeValue); | |
return layerList; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment