Android - How do I remove the ugly borders on imagebuttons? - android

http://i.imgur.com/WCGjcOe.png
Pretty straight up question - How do I remove those grey borders?
The pictures (.png files) are just the stars, text and the white around it. Then when I add them as imagebuttons they add this ugly grey borders that I really don't want.
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/starButton1"
android:src="#drawable/star_pink_1"
android:onClick="starButton1Clicked"
android:layout_below="#+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

You have to define the xml attribute background to Your ImageButton:
android:background="#android:color/transparent"
what You see is the original button, Your src is just overlayed.

try this
android:background="#null"
this will make your imagebutton with no background.

Both codes work fine for your query :
android:background="#null"
OR
android:background="#android:color/transparent"

Use this
style="?android:attr/borderlessButtonStyle"

Related

Remove whitespace in imagebutton

In my Image Buttons, there is a lot of white space around the source image. Is it possible to remove this space so that the imagebutton just surrounds the source image itself.
<ImageButton
android:id="#+id/story_1"
android:src="#drawable/my_story"
style="?android:attr/borderlessButtonStyle"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:contentDescription="Add my story" />
Try this
<ImageButton
android:id="#+id/story_1"
android:src="#drawable/my_story"
style="?android:attr/borderlessButtonStyle"
android:background="#null"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:contentDescription="Add my story" />
Probably the problem caused by the image transparency. Try remove the white spaces around the image and make those areas transparent.
make sure the original image you are using doesn't have too much white since you already have the solution in your xml scaleType="fitXY" you can try scaleType="fitCenter" but your image is already stretched to fit your entire button in the orginal code

getting rid of extra space that comes with android's default buttons

I've placed three buttons side by side using constraints, with 4dp gap between each as shown below, but due to this "extra space"(shown below), the actual gap between buttons looks greater than it is:
What is the attribute that android uses to maintain this space? How can I remove it. I'm using the default <Button> widget that is android's default button widget.
Add this attribute to the buttonstyle="#style/Widget.AppCompat.Button.Borderless". This will make your button white and borderless. After add background to your button using this. android:background="#android:color/darker_gray"
Your button should be as below.
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
style="#style/Widget.AppCompat.Button.Borderless"
android:background="#android:color/darker_gray"/>
Add Background to your Button and this space will cover by the background color.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#color/colorPrimary"
android:padding="2dp"
android:layout_margin="4dp"/>
You can also use translationX and translationY property.

how to set image as background button

I am new in Android development.I created a simple project with a simple button.I'd like to set image as background (see image). I've used android:src="#drawable/id_image" and android:background="#drawable/id_image2" but the image does not appear on the entire surface of button.Any help would be appreciated
Android, you can use android.widget.ImageButton to display a normal “Button“, with a customized background image.
<ImageButton
android:id="#+id/top_bar_btn_right_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/ic_filter" />
You might use android:src and android:background for adding two images.
when you add your button , you just go to the menu of properties and choose background / drawable and choose your image
You can try something like this
<RelativeLayout
android:layout_width="250dp"
android:layout_height="400dp"
android:background="your_background_goes_here"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="your_icon_above_background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text_for_your_image"/>
</RelativeLayout>

How to remove the square border from a image button

I have an image button shape like a 'star' and i what the clickable area to be only the 'star' but instead of that i have a transparent square clickable area around the 'star', can anyone please tell me how to remove the square bcoz the next 'star' it's close and the square overlaps the first 'star'.
thank you so much
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="190dp"
android:layout_marginBottom="180dp">
<ImageButton
android:id="#+id/star"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#drawable/star"
/>
Instead of ImageButton you can user ImageView and make in clicable.
Set
android:background=#android:color/transparent
and insert
android:src=#drawable/star
Or just use an ImageView instead, because you can have OnClickListener on both, therefore they could also function as described in your question.
You can use:
android:background="#null"
in the imageButton tag.

Android ImageButton: image with tranparent background

i want to write an application where the user can change the color scheme. I have Imagebuttons and the images on the buttons are pngs and have transparent background. but when i place them on the buttons they are not transparent anymore. could anybody help me with some code?
thanks!
Anne
Are you ensuring that android:background="#null" is set? Otherwise you'll have the gray button background. For example:
<ImageButton
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_transparent_png"
/>
write your layout for ImageButton as:
<ImageButton
android:src="#drawable/your_image"
android:id="#+id/your_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"/>
Hope this helps!

Categories

Resources