1

How can a layer be removed from LayerDrawable? addLayer can be used to add a layer, but I don't see a function that can be used to remove a layer.

https://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html

edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267

2 Answers2

3

After looking at documentation there is no direct method to remove a layer. however method public void setDrawable (int index, Drawable drawable) can be used to change drawable of a layer so may be replacing a layer with an empty (transparent or null) drawable will give you desired result.

Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78
3

You can make the layer transparent by setting the alpha value to zero:

  //ld is of LayerDrawable type
Drawable layer = ((LayerDrawable)(ld)).getDrawable(index);
layer.mutate().setAlpha(0);
nitinr708
  • 1,393
  • 2
  • 19
  • 29
Maya
  • 349
  • 3
  • 15