Android examples for Graphics:Drawable
There's a limitation where we can only get the current Drawable, so that's the only one that can be mutated
//package com.java2s; import android.graphics.Shader.TileMode; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.StateListDrawable; public class Main { /** There's a limitation where we can only get the current Drawable, so that's the only one that can be mutated **/ private static void fixStateListRepeat(StateListDrawable d) { fixDrawableRepeat(d.getCurrent()); }/*from w w w .java2 s . c om*/ /** Dispatches Drawable repeat fixes based on the type of the Drawable **/ public static void fixDrawableRepeat(Drawable d) { if (d != null) { if (d instanceof BitmapDrawable) fixBitmapRepeat((BitmapDrawable) d); else if (d instanceof LayerDrawable) fixLayerRepeat((LayerDrawable) d); else if (d instanceof StateListDrawable) fixStateListRepeat((StateListDrawable) d); } } /** Mutate the bitmap and reset tilemode **/ public static void fixBitmapRepeat(BitmapDrawable bmp) { bmp.mutate(); // make sure that we aren't sharing state anymore bmp.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); } /** Go through layers and dispatch them via fixDrawableRepeat **/ public static void fixLayerRepeat(LayerDrawable lyr) { for (int i = 0; i < lyr.getNumberOfLayers(); i++) { fixDrawableRepeat(lyr.getDrawable(i)); } } }