开发者

Issue with image having transparent background in Android

开发者 https://www.devze.com 2023-02-10 23:39 出处:网络
I\'m creating a custom dialog with a background image which has rounded corners. I remove the white border using a custom style, but it\'s displayed开发者_如何学运维 as if a black rectangle of the sam

I'm creating a custom dialog with a background image which has rounded corners. I remove the white border using a custom style, but it's displayed开发者_如何学运维 as if a black rectangle of the same size was behind my image, as shown below (the background image of the dialog is the brown one):

Issue with image having transparent background in Android

How can I keep the transparent background of my image with the round corners?

Layout of my dialog:

<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"   
>
...

I remove the white border by applying the following style to my dialog:

<style
name="Theme_Dialog_Translucent"
parent="android:Theme.Dialog">
<item name="android:windowBackground">@null</item>
</style>

My CustomDialog class is:

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

...

}


The problem is in the windowBackground attribute Try using this

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

This will make the window background transparent.

I hope that solves the issue

0

精彩评论

暂无评论...
验证码 换一张
取 消