【问题标题】:Issue with image having transparent background in AndroidAndroid中图像具有透明背景的问题
【发布时间】:2011-02-17 21:34:57
【问题描述】:

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

如何让图片的透明背景与圆角保持一致?


我的对话框布局:

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

...

}

【问题讨论】:

    标签: android image dialog transparent


    【解决方案1】:

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

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

    这将使窗口背景透明。

    希望能解决问题

    【讨论】:

    • 是的,它确实解决了问题!谢谢你。我无法直接设置十六进制值,我必须使用 ​​@color/transparent 设置它,并使用 #00000000.
    • 是的,这是一个更好的做法,为了简单起见,我使用了这些术语,我很高兴它有所帮助:)
    猜你喜欢
    • 1970-01-01
    • 2010-11-22
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 2015-05-15
    • 2014-02-27
    相关资源
    最近更新 更多