Droid Genie Droid Genie - 6 months ago 9
Android Question

ImageButton Not Showing transparency even it is in PNG Format

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??

Answer

add this in your ImageButton Layout

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