简体   繁体   中英

Android Studio and PNG vector images

Creating vector images in Photoshop (for transparent backgrounds). When I add them as the image source for my ImageButtons, and run the app, the image displays with a white background.

Can't find any useful info on why the images are not coming out transparent through the app.

Are there some additional steps/coding required to make vector images work properly? I can't see why.

Example code, as requested:

<ImageButton
    android:id="@+id/btnGameUp"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:src="@drawable/arrowright"
    android:adjustViewBounds="false"
    android:clickable="true"
    android:cropToPadding="false"
    android:padding="0dp"
    android:scaleType="fitXY"
    android:layout_marginLeft="270dp"
    android:layout_marginTop="260dp" />

No one came to help us, but we managed to find the solution on our own after hours of crying and holding each other for comfort.

In the layout xml file, you need to add the following line to each vector object:

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

That's it! Tested and working perfectly. Hope this helps someone.

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