I created a custom button and I saved it as a .png with a transparant background.
this is the code in xml
<Button
android:id="#+id/btnReport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:drawableTop="#drawable/report" />
and when i run it in the emulator I get my button with a grey background
(I cannot post images yet, because my reputation is too low. Apologies for this)
How do I make the background transparant?
Thanks.
Vincent
You should be doing
android:background="#drawable/report"
is that image "report" only transparent? You donĀ“t need to set a transparent image, just set
android:background="#android:color/transparent"
to your button.
Related
I am very new to Android Studio and creating apps in general.
I have created an Image Button and uploaded an Image, problem is that I want to make the background of the Button transparent.
This is what I mean:See Example
The background of the left button is black and I want to make it transparent, like the Right Button.
Just put this property inside ImageButton tag:
android:background="#android:color/transparent"
----------OR--------------
You can also user vector image for this:
Click on Vector Asset
Click on small icon image(just below ic_android_black_24dp)
Search any icon and add to your drawable. The icon you are using is appeared in search result. use this list icon.
Try This
<ImageButton
android:layout_width="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/image"
android:layout_height="wrap_content" />
Hello Guys I need some help in creating Imagebutton. I created custom button on PS and then saved it in PNG format with transparent background. After that i patched my image with 9patch. Now i am using that image as a button in my layout but the image is showing colored background corners. I tried alot of things but its not removing.
Here is my XML
<ImageButton
android:id="#+id/mybutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/registerbutton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="123dp" />
Keep the background attribute as #null like this :
android:background="#null"
If still you are getting that corner, it might be from the png file that you are using.
This is an example of what i get from #null
Probably the ouput of "9patching" operation added corners. Open the file and check if there are corners or not.
If that won' help, try switching android:src attribute with android:background attribute.
And u can make .png button online using this site
I'd like to have an image in a button with text and I've already have it. But the problem is that my image is with some " grey background colour" (as you can see below) that I would like to remove.
In a normal situation I would use android:background="#null" and it would solve it, but I'm using as background a template to my button.
<Button
android:drawableLeft="#drawable/profile_32"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp"
android:textColor="#color/yellow3"
android:background="#drawable/buttons2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="#string/button_profile"
android:textSize="18dp"
android:textStyle="bold"
android:id="#+id/buttonProfile"
/>
Does anyone know any other way to remove that grey background color from the image? Thanks.
Is the grey actually part of the image? If not you could try background:"#android:color/transparent"
If the grey background is part of the profile_32 image, there is not an easy way to remove it in Android. You will need to have the image re-exported or use an image editing program to remove the background.
Yes, use an ImageButton and just add
android:background="#00000000"
or
android:background="#null"
to your Button.
The first 2 "0" is alpha, "00" = trasparent
Here is a picture that will help you understand my problem:
I want to stretch the image shown inside ImageButton to the whole area of the ImageButton.
As you can see, the picture with the number 1 only take about 95% of the ImageButton and you can also see the boundaries of the ImageButton.
I still want to maintain the image button style
Here's how I am using ImageView:
<ImageButton
android:id="#+id/secondActivityBbuttonDownRight"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:scaleType="fitStart"
android:src="#drawable/111" />
I think I found out what is my problem.
I need a custom component that can contain only an image and have a clicking effect.
ImageButton is ImageView.
If you want your image to fill button
than set android:scaleType="fitXY", so the image you set in android:src will be stretched to fill whole image button.
ImageButton has a background under your image and padding.
If you do not want background
set android:background="#android:color/transparent".
If you do not want padding
set android:padding="0" or set background without padding.
You can also use
android:scaleType="centerCrop"
android:padding="0dp"
android:scaleType="fitXY" tested and works correctly.
Use below code :-
<ImageButton
android:id="#+id/secondActivityBbuttonDownRight"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:scaleType="fitStart"
android:background="#drawable/111" />
You should consider creating a 9-patch image to make the image fit correctly on an ImageButton in case you need to stretch it, but you don't want the image to become distorted.
To have a button with an image that completely covers it, you can use something like this:
<ImageButton android:id="#+id/iconBtn"
android:layout_width="64dip"
android:layout_height="64dip"
android:src="#drawable/icon_button"
android:scaleType="fitCenter"
android:background="#00000000"/>
For a full tutorial on creating buttons with custom skins and the use of selectors to manage their states, you can check a tutorial I've written some time ago here (Creating a custom Android button with a resizable skin).
If your image "111" has no padding itself then simply use android:background"#drawable/111"
Just set this two attributes on the ImageButton:
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="centerCrop"
With those, you will get the provided src to be stretched, and also if you put some specific width and height on that ImageButton you won't get a rectangle around it.
I'm using two toggle buttons on my application, when I run it on the emulator the button has black text, and a light gray background. As we can see in the next image:
When I run it on my real device the button has another style, it has white text, and a black background. As shown in the next image.
My QUESTION IS: How to change the style of a ToggleButton to it always stay with a clear gray background, as in the first image? Is it defined by a Theme?
The xml code used for the button was:
<ToggleButton
android:id="#+id/toggleButtonSimulado"
android:layout_gravity="center|top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="On"
android:textOff="Off" />
Style of the button or any other view changes in the real device according to the current theme selected on that device. To prevent this you need to specify background color and text color explicitly. Use a gradient as the background of the button. For example:
<ToggleButton
android:id="#+id/toggleButtonSimulado"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/gray_gradient"
android:textOn="On"
android:textOff="Off"
android:textColor="#android:color/black" />
You can use your own backgrounds for the buttons.
Search btn_toggle_off.9.png/btn_toggle_on.9 on your sdk install dir(android-sdk-mac_86/platforms/android-9/data/res/drawable-hdpi).
And make sure to copy the selector located on drawable folder
Or you can try:
androiddrawables
androiddrawablesexplorer
Hope this help.