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?
Create a resource in drawable (like files_bg. xml) folder and set it as background for layout. Use two item in layer list, one for solid color in shape and other one bitmap. and now set drawable as background in layout or wherever you are using it.
Use app:drawableTint="@color/yourColor" in the xml instade android:drawableTint="@color/yourColor" .
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With