在Android中,图像具有透明背景的问题

4
我正在创建一个带有圆角背景图片的自定义对话框。我使用自定义样式来删除白色边框,但它显示为如果黑色矩形与我的图片大小相同一样,如下所示(对话框的背景图是棕色的):
如何保持我的圆角图片的透明背景?
我的对话框布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/confirmation"
android:orientation="vertical"
android:background="@drawable/dialog_background"
android:layout_width="279dp"
android:layout_height="130dp"   
>
...

我通过将以下样式应用于我的对话框来去掉白色边框:

<style
name="Theme_Dialog_Translucent"
parent="android:Theme.Dialog">
<item name="android:windowBackground">@null</item>
</style>

我的CustomDialog类是:

public class CustomDialog extends Dialog implements OnClickListener {
Button okButton;

public CustomDialog(Context context) {
    // Custom style to remove dialog border - corners black though :(
    super(context, R.style.Theme_Dialog_Translucent);
    // 'Window.FEATURE_NO_TITLE' - Used to hide the title
    requestWindowFeature(Window.FEATURE_NO_TITLE);      
    setContentView(R.layout.custom_dialog);
    okButton = (Button) findViewById(R.id.button_ok);
    okButton.setOnClickListener(this);
}

...

}
1个回答

6
问题出现在windowBackground属性中。尝试使用以下内容:
<item name="android:windowBackground">#00000000</item>

这将使窗口背景透明。
希望这解决了问题。

2
是的,它解决了问题!谢谢。我无法直接设置十六进制值,但我必须使用<item name="android:windowBackground">@color/transparent</item>进行设置,并创建一个color.xml文件,其中包含<color name="transparent">#00000000</color>。 - jul
是的,这是更好的实践。我使用这些术语只是为了简单明了,很高兴它对你有帮助 :) - raukodraug

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接