I have an Android activity which has three buttons. I have set a color for the main activity LinearLayout
's background via:
android:background="@color/homeBgColor"
I want to put up a translucent background image behind the buttons on the activity. I tried using an ImageView
, but it pushes the buttons down.
Is there any way to set the background color as well as image for the activity, like we do in CSS?
#mydiv{ backround: #262626 url("link-to-my-img.png");}
Thanks
android:windowIsTranslucent indicates weather the window in which the activity is present in translucent state or not. It must be a boolean value i.e. it can be true or false. android:windowBackground is used to set the background of the main window. Here, we are setting the background as transparent.
You should be able to achieve this with a <layer-list />
drawable. Within it, place an <item />
which contains a <bitmap />
(example stolen from the developer docs):
<item>
<bitmap android:src="@drawable/image"
android:gravity="center" />
</item>
Then, your other item can just be a solid color. Make a drawable resource that just has that solid color in it, 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 flip the order of the <item />
tags, I forget which is on top.)
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