skip to Main Content

I designed a button in photoshop cs6 and save it as a png image. When try to add it in android studio as an imageView or imageButton it includes the background color. I tried android:backgroud="@android:color/transparent" but no luck.

<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/screenTextView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_weight="1"
        android:background="#BDBDBD"
        android:ems="10"
        android:fadingEdge="none"
        android:hint="0"
        android:inputType="none"
        android:textAlignment="viewEnd"
        android:textSize="30sp" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="0dp"
        android:layout_height="160dp"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        app:srcCompat="@drawable/buttonn1" />
</LinearLayout>

EDIT : https://github.com/Gamer1989/project/issues/1 You can see the images from here.

3

Answers


  1. This works for me. If it dont works for u you should consider that there is a issue with ur png. Are u using a importer to add images to ur project? For example Batch Drawable Importer.

    <LinearLayout 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"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <EditText
                android:id="@+id/screenTextView"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:layout_weight="1"
                android:background="#BDBDBD"
                android:ems="10"
                android:fadingEdge="none"
                android:hint="0"
                android:inputType="none"
                android:textAlignment="viewEnd"
                android:textSize="30sp" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <ImageView
                android:id="@+id/imageButton"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:padding="20dp"
                android:src="@drawable/buttonn1" />
        </LinearLayout>
    </LinearLayout>
    Login or Signup to reply.
  2. It means the png file does not have a transparent background. Be sure the referred file does have this feature.
    This link teaches how to do it.

    Login or Signup to reply.
  3. You can open your designed photoshop file into Adobe XD and then select your shapes/button that you wants to export, export those in png format, after that you can copy them into android studio drawable folder and you can use it. No background colour will be included like before.

    PNG shapes exported from Photoshop:

    shape-photoshop

    Same shapes exported from Adobe XD:

    shape-adobe-xd

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search