I am new to android development and am developing my first android application. I have the background color of the View set in the layout's xml as follows.
android:background="#+color/bgColor"
Now, i have a full sized transparent background image that i want to lay over the background and then other Elements over that image.
is there a way i can use both background color and background image in the same layout.
Thanks in Advance.
You can use an ImageView with a background color:
<ImageView
layout_width="match_parent"
layout_height="match_parent"
src="#drawable/myImage"
background="#color/myBgColor" />
Another option is to set the background color in the root element of your layout, and keep the src in your ImageView.
I'm using AppCompatImageView. In this background color can be set using the below property.
android:backgroundTint="#color/colorPrimary"
Related
I want change background for whole app except textviews.
So, I change style.xml
<item name="android:background">#color/colorRed</item>
But textviews change background too. For example, toast text appear on red background. As I understand, default textview background is transparent. Is there posibilitiy to change background without textviews?
Just add a background (android:background) to the text view on the xml file, like this
<TextView
android:background="android.R.color.white"
That background will not change because it's fixed.
I have an icon I would like to scale down to 48dp and use as a button (no background). However, adding the android:background attribute (to make the background transparent) seems to break the sizing I have applied to the button and it displays at its full size:
Desired size but with ugly background:
<ImageButton
android:id="#+id/composition_send"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:scaleType="fitCenter"
android:src="#drawable/ic_send_black_48dp"/>
Full (wrong) size, but with no background (desired):
<ImageButton
...
android:background="?android:selectableItemBackground"/>
Why does adding that one line ruin the sizing?
try to add
android:src="#drawable/ic_send_black_48dp
android:backgroundTint="#0000"
to ImageButton, it will make the background transparent and then you can set the image on it.
When you don't set the background property for the Imagebutton, the Imagebutton will use the default Imagebutton background of Android. And this background contains the padding so your image is smaller.
So when you set the background for Imagebutton by a color or resource that doesn't contain padding, your image will look larger
You can find the default background of the Imagebutton and another View in
..\Android\sdk\platforms\android-23\data\res\drawable\
(Some resource in this is not public)
For example
If you compile your project with API 23, the default background of ImageButton is btn_default_material
<ImageButton
...
android:background="#android:drawable/btn_default_material"
android:src="#drawable/ic_send_black_48dp"/>
<ImageButton
...
android:src="#drawable/ic_send_black_48dp"/>
So you set the android:background="#android:drawable/btn_default_material" or don't use background property, 2 ImageButton will look same (note: btn_default_material is not public for use)
Hope this help
If you don't want that ugly background in imagebutton,then you can use an imageview as button and set onClickListener on it. It will behave like a button.
This Link will be helpful to you.
Hi guys I am new to Android .I want to make the layout given in the image.
I want to achieve the effect inside the red box.How can I make the background opaque while its keep its child opaque?
I tried this as,
The part inside the red box as RelativeLayout, which has a TextView (value as Contact details) I gave android:alpha=0.3 for relative layout,but the problem is,it makes the TextView also opaque (which is logical)
I just want some thoughts to move in that direction.
Create a color resource with an alpha component of 0.3 and set it as the background of the RelativeLayout
In the colors.xml
<color name="opaque_black">#4c000000</color>
In the layout of the View
<RelativeLayout
...
android:background="#color/opaque_black"
...>
I have custom notification with linear layout that contains four image buttons.
I set the linear layout background color to transparent color #00000000 and also i set the background color of the four image buttons to transparent color #00000000.
As Expected, According to the transparent color of linear layout and image buttons, my custom notification background color must match the emulator notification background color(almost gray).
but actually the background of notification is still black.
My minimum sdk is 11 and target is 19
Note that the other previous questions not solved my problem.
Thanks in advance, Mostafa.
Try to use in your XML file
android:background="#android:color/transparent"
instead of #00000000
I have an activity with its layout set to an XML file. the root layout is a RelativeLayout and i am setting the background to this layout via rootLayout.setBackgroundResource(R.drawable.default_background);
this drawable, R.drawable.default_background has some transparency in it.
It seems as though the default background of any layout is black. when i set the background to this drawable resource, the default black background seeps through the semi-transparent drawable.
How can i change the default background behind this drawable to white instead of black?
edit: i do not want to change the theme, as that changes more than just background
Make the root view of the layout a FrameLayout which contains your RelativeLayout, and make the FrameLayout's background white.