Is it possible to use drawable+color as background?

android

Solution

Sure. Just use a LayerListDrawable.

Something like:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="#FF00ffff" />
        </shape>
    </item>
    <item>
         <bitmap 
             android:src="@drawable/your_tiled_drawable"
             android:tileMode="repeat" />
    </item>
</layer-list>

Save that in your `res/drawables` directory, and use it as your background.

Sadly, if your application is more complicated, sometimes the tileMode will get unset for no apparent reason. If you run in to that, you'll have to re-add the tile mode in Java.

I usually still set it in xml, and then do something like:

View v = findViewById(R.id.my_view);
LayerDrawable lld = (LayerDrawable) v.getBackground();
BitmapDrawable tiled = (BitmapDrawable) lld.getDrawable(1);
tiled.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);

Problem

I have an opaque pattern (10% opacity) and I need to combine it with some color. Is it possible to set background color to image?

Original source