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

标签 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);
}

...

}

最佳答案

问题出在 windowBackground 属性中 试试这个

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

这将使窗口背景透明。

希望能解决问题

关于android - Android 中具有透明背景的图像问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5034947/

相关文章:

android - 如何在 Eclipse ADT 中修复我的 AVD?

android - 如何在布局编辑器中模拟沉浸式模式

php - 在 PHP 中以行/表格形式显示从 MySQL 检索的数据

android - 如何更改对话框的颜色

python - QDialog 未从主窗口打开(pyQt)

jQuery UI slider 问题

android - SurfaceView 未显示

java - 解析 JSON Android ArrayList

CSS 图像垂直对齐

android - 如何在android sdk中从图库中获取图像并将其显示到屏幕上