我正在创建一个带有圆角背景图像的自定义对话框。我使用自定义样式删除了白色边框,但它显示为好像在我的图像后面有一个相同大小的黑色矩形,如下所示(对话框的背景图像是棕色的):
我怎样才能使我的图像的透明背景保持圆角?
我的对话框布局:
<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/