简体   繁体   English

使用 Android Studio 时 PNG 透明背景显示为黑色

[英]PNG transparent backgrounds appearing black when using Android Studio

The social icons below (for fb, twitter, mail and share) are circular PNGs with transparent backgrounds.下面的社交图标(用于 fb、twitter、邮件和分享)是具有透明背景的圆形 PNG。 When I use the code and exact same images in Eclipse, I get transparent background but when build and run with Android Studio, I get black backgrounds.当我在 Eclipse 中使用代码和完全相同的图像时,我得到透明背景,但是当使用 Android Studio 构建和运行时,我得到黑色背景。 See details below.请参阅下面的详细信息。

Images are the same.图像是一样的。 Code used in layout xml files:布局xml文件中使用的代码:

 <LinearLayout
                android:id="@+id/ll_shareBtns"
                android:layout_width="@dimen/sharesection_width"
                android:layout_height="@dimen/sharesection_height"
                android:layout_gravity="center"
                android:background="@drawable/bg_sharebox"
                android:gravity="center"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/btn_facebook"
                    android:layout_width="@dimen/dimens_sharebtns"
                    android:layout_height="@dimen/dimens_sharebtns"
                    android:layout_marginLeft="@dimen/sharebtns_leftmargin"
                    android:layout_marginRight="@dimen/sharebtns_rightmargin"
                    android:background="@drawable/bg_facebookbtn"
                    android:gravity="center" />

                <Button
                    android:id="@+id/btn_twitter"
                    android:layout_width="@dimen/dimens_sharebtns"
                    android:layout_height="@dimen/dimens_sharebtns"
                    android:layout_marginLeft="@dimen/sharebtns_leftmargin"
                    android:layout_marginRight="@dimen/sharebtns_rightmargin"
                    android:background="@drawable/bg_twitterbtn"
                    android:gravity="center" />

                <Button
                    android:id="@+id/btn_email"
                    android:layout_width="@dimen/dimens_sharebtns"
                    android:layout_height="@dimen/dimens_sharebtns"
                    android:layout_marginLeft="@dimen/sharebtns_leftmargin"
                    android:layout_marginRight="@dimen/sharebtns_rightmargin"
                    android:background="@drawable/bg_emailbtn"
                    android:gravity="center" />

                <Button
                    android:id="@+id/btn_share"
                    android:layout_width="@dimen/dimens_sharebtns"
                    android:layout_height="@dimen/dimens_sharebtns"
                    android:layout_marginLeft="@dimen/sharebtns_leftmargin"
                    android:layout_marginRight="@dimen/sharebtns_rightmargin"
                    android:background="@drawable/bg_sharebtn"
                    android:gravity="center" />
            </LinearLayout>

When code compiled and run with Android Studio, I see this:当代码编译并使用 Android Studio 运行时,我看到:在此处输入图片说明

When code is compiled and run with Eclipse, I see this:当代码编译并使用 Eclipse 运行时,我看到:

在此处输入图片说明

Quite Strange.很奇怪。 Could difference in build tools version cause this problem too?构建工具版本的差异也会导致这个问题吗?

Its seems to be problem in Theme used in xml file .它似乎是 xml 文件中使用的主题中的问题。

-check it once if the theme is different in eclipse and Android Studio then you can correct it. - 如果 eclipse 和 Android Studio 中的主题不同,请检查一次,然后您可以更正它。

by changing the Theme on file style.xml通过更改文件 style.xml 上的主题

Hope this will helpful .thanks希望这会有所帮助。谢谢

Did you try testing your app in a device?您是否尝试在设备中测试您的应用? This is a known bug with Android Studio where icon PNGs show a black box despite being transparent.这是 Android Studio 的一个已知错误,其中图标 PNG 尽管透明,但仍显示黑框。 I faced the same issue where I saw a black box background in Android Studio layout design preview but the image rendered correctly in the device.我遇到了同样的问题,我在 Android Studio 布局设计预览中看到黑框背景,但图像在设备中正确呈现。 This link can give you more confidence - ic_stop_white_*dp.png background is black, not transparent这个链接可以让你更有信心 - ic_stop_white_*dp.png 背景是黑色的,不是透明的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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