Android: set background color and translucent background image to Activity

I have an Android activity that has three buttons. I set the color of the main background of LinearLayout with:

 android:background="@color/homeBgColor" 

I want to put a translucent background image behind the buttons in action. I tried using ImageView , but it pushes the buttons down.

Is there a way to set the background color as well as the image for activity, as in CSS?

 #mydiv{ backround: #262626 url("link-to-my-img.png");} 

thanks

+7
source share
1 answer

You can achieve this with <layer-list /> drawable . In it, place <item /> , which contains <bitmap /> (an example stolen from the documentation of the developer):

 <item> <bitmap android:src="@drawable/image" android:gravity="center" /> </item> 

Then your other item may just be a solid color. Create a resource that has only that solid color, and then combine them:

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/your_color" /> <item> <bitmap android:src="@drawable/image" android:gravity="center" /> </item> </layer-list> 

(You may have to reverse the order of the <item /> tags, I forgot what’s on top.)

+22
source

All Articles