-1

I am creating an app which have an ImageButton in the Center. The problem is that I am not getting a transparent image inside the imagebutton even the image is in pure PNG format.

My Xml is as follows

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="switchmode.lteonly.lteonlyswitch.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:clickable="true"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:src="@drawable/myimage"
        android:onClick="onClick"/>


</RelativeLayout>

The output Layoutis as follows.

enter image description here

Any Idea how to resolve this??

Droid Genie
  • 351
  • 4
  • 15

4 Answers4

6

add this in your ImageButton Layout

android:background="@android:color/transparent"
Abhishek Patel
  • 4,280
  • 1
  • 24
  • 38
2

add this to ImageButton

android:background="@null"
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
1

1) I guess your png-file is not transparent. (Only because it's PNG it does not mean, the background is transparent). Check if it there is an alpha channel in the picture und there is no backgroundcolor in the image itself.

2) If this image is actually transparent try to add

android:background="@android:color/transparent" 

to the ImageButton

Dominik Vincenz
  • 445
  • 3
  • 10
1
Add this to your imageButton
 android:background="#00000000"
MurugananthamS
  • 2,395
  • 4
  • 20
  • 49