Wednesday, May 17, 2017

Change the Background Color on Run-time/Pragmatically of Shape Draw-able in Android.


How to Change the Background Color on Run-time/Pragmatically of Shape Draw-able in Android.

GradientDrawable gradientDrawable = (GradientDrawable) myView.getBackground();//To change the solid color
gradientDrawable .setColor(yourColor)

//To change the stroke color
int width_px = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
gradientDrawable .setStroke(width_px, Color.Black);

No comments:

Post a Comment