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" />
Related
I have been trying to achieve the Normal android button effects when the button is already set with a background image
But the problem is, once the background is set, the button default nature is gone (shadows, clickable animation etc..)
Can Someone please give me a working solutions for this?
Here's the code to my button
<Button style="#style/Widget.AppCompat.Button.Colored"
android:id="#+id/student"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/student"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintVertical_bias="0.891" />
It looks amazing since I have set a background image but It still looks like you have set an image to a jLabel in Java)
How can I get the default button looks while keeping my background image intact?
Button works by setting the background to a background with the elevation, shadows, ripple, etc. To get the same behavior, you're going to need to set your background to a StateListDrawable that performs the ripple effect and puts the shadows and elevation effects with your image as the background inside of all that. You can't just set the background to be your image, that will lose all of those features. The easiest way to get that right is to look at the AOSP source code and find the drawable it uses, copy it to your project, and edit appropriately.
Basically in Android a Button is just a TextView with a special background preset.
Why don't you use ImageButton widget ? It has the same behaviour as a Button and ImageView combined
Check this tutorial to see how to work with it.
as mentionned in the official documentation
Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button, with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the XML element or by the ImageView.setImageResource(int) method
Currently I have a button that looks like this:
What I want to do is to be able to replace the text with this vector drawable but keep the blue rectangle background:
I looked into doing this but I cannot seem to get it right.
I tried the following combination:
<Button
android:id="#+id/deletebutton"
android:layout_width="0dp"
android:layout_height="50dp"
android:src="#drawable/deletebtn24dp"
android:backgroundTint="#color/primaryButtonColor"
android:layout_weight="1"/>
However that just led to a blank blue button with no drawable. What can I do so the drawable replaces the text?
Also I would like to support API levels start at 16+.
You have to use app:srcCompat="#drawable/deletebtn24dp" instead of android:src="#drawable/deletebtn24dp". Using an ImageButton might also be better than using a straight Button.
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
I have an image which I want to use as a button. But I want only the image to be visible as the button, with the shape of the image (I do not want the regular button around the image, nor I want the regular button shape). How can I achieve this? Can I achieve this without designing a custom button?
Check the android developers reference and Tutorial Custom Button. It's exactly what you need!
Set the image with button.setBackgroundDrawable (or Resource, etc.)
Use ImageButton with background property set to some color i.e. #000 and no padding
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" android:background="#drawable/ic_launcher"/>
One of the application in my mobile has a header like the one shown below in the snapshot. I like the design very much and would like to create one for my application. Clicking the home icon takes the user to landing page(Home page). I have only created buttons of squarish and rounder corners. But not sure, how to create one like the one given below. Any help would be highly appreciated.
Create the image in photoshop or whatever.
Then create an imageview and let it act like a button:
<ImageView
android:id="#+id/camera_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/button_camera"
android:onClick="onCameraButtonClick" />
onClick is introduced in Android 1.6
or a button and set the background:
<Button
android:id="#+id/camera_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_camera"
android:onClick="onCameraButtonClick" />
drawable/camera_button should be a state drawable so the user can see when it is being clicked/focused.
in your activity:
public void onCameraButtonClick(View v){
// Do Something
}
It's all here:
http://developer.android.com/reference/android/widget/Button.html
The way that I would do this is just create the buttons in photoshop/GIMP on the same canvas then save each as PNG, you can use the slice tool for this. Then I would just add an attributes to each button. There's attributes that let you set the left margin of say the right button to line up with the right margin of the left button. The backgrounds of the buttons could also be patch9 images, and the icons inside it could be the src attribute of the button view. The button with the camera would have SRC pointing to a PNG that has the camera icon as well as "Camera". And the button itself not having any text.