Problem with image having transparent background in Android

I am creating a custom dialog with a background image with rounded corners. I delete the white border using a custom style, but it appears as if there was a black rectangle of the same size behind my image as shown below (the background image of the dialog is brown):

enter image description here

How can I keep the transparent background of my image with 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:

 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); } ... } 
+4
source share
1 answer

The problem is with the windowBackground attribute windowBackground Try using

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

This will make the window transparent.

I hope that solves the problem

+6
source

Source: https://habr.com/ru/post/1340237/


All Articles