简体   繁体   中英

Android Studio background color are included in png image

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.

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>

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.

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:

形状-photoshop

Same shapes exported from Adobe XD:

形状-adobe-xd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM