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

时间:2011-02-17 21:34:57

标签: android image dialog transparent

我正在创建一个带有圆角的背景图片的自定义对话框。我使用自定义样式删除白色边框,但它显示为好像我的图像后面有一个相同大小的黑色矩形,如下所示(对话框的背景图像是棕色的):

enter image description here

如何使用圆角保持图像的透明背景?


我的对话框布局:

<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 个答案:

答案 0 :(得分:6)

问题出在windowBackground属性中 尝试使用此

<item name="android:windowBackground">#00000000</item>

这将使窗口背景透明。

我希望能解决问题

相关问题