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

jul*_*jul 4 android dialog image transparent

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

在此输入图像描述

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


我的对话框的布局:

<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"   
>
...
Run Code Online (Sandbox Code Playgroud)

我通过在我的对话框中应用以下样式来删除白色边框:

<style
name="Theme_Dialog_Translucent"
parent="android:Theme.Dialog">
<item name="android:windowBackground">@null</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的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);
}

...

}
Run Code Online (Sandbox Code Playgroud)

rau*_*aug 6

问题出在windowBackgroundTry using this属性中

<item name="android:windowBackground">#00000000</item>
Run Code Online (Sandbox Code Playgroud)

这将使窗口背景透明.

我希望能解决这个问题

  • 是的,它确实解决了这个问题!谢谢.我无法直接设置十六进制值,我必须使用<item name ="android:windowBackground"> @ color/transparent </ item>设置它,并使用<color name ="创建一个color.xml文件透明">#00000000 </颜色>. (2认同)