Search code examples
androiddrawablelayer-list

How to use findDrawableByLayerId in android?


I want to use setBounds() to a specific item in layer-list, which is used as a background for a button. But I am not able to get the LayerDrawable object to call findDrawableByLayerId().

Can anybody help to solve this ?


Solution

  • used this method to create on new layerdrawable :) I could no use findDrawableByLayerId() :(

    @Override
    public void setBackgroundDrawable(Drawable background) {
        Log.d("button","setting new background  ");
        Drawable[] layers = new Drawable[5];
        Resources resources = getResources();
    
        layers[0] = resources.getDrawable(R.drawable.outer_rectangle);
        layers[1] = resources.getDrawable(R.drawable.inner_rectangle);
        layers[2] = resources.getDrawable(R.drawable.upper_ovel);
        layers[3] = resources.getDrawable(R.drawable.gradient_fill);
        layers[4] = resources.getDrawable(R.drawable.lower_ovel);
    
        LayerDrawable layerDrawable = new LayerDrawable(layers);
    
        layerDrawable.setLayerInset(0, 0, 0, 0, 0);
        layerDrawable.setLayerInset(1, 3, 3, 3, 0);
        layerDrawable.setLayerInset(2, 3, 15, 3, 25);
        layerDrawable.setLayerInset(3, 3, 23, 3, 0);
        layerDrawable.setLayerInset(4, 4, 60, 4, -5);
    
        super.setBackgroundDrawable(layerDrawable);
    }