6

I'm trying to create a Layout with rounded corners and I used shape to help me do so, but when adding the rounded corners, the background white color also stays.

It might be also important to note that I am using this layout.xml as ContentView for Dialog:

final Dialog MyDialog = new Dialog(this);
MyDialog.setContentView(R.layout.layout.xml);

This is my layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="300dp"
    android:background="@drawable/round_corners"
    android:layout_height="200dp">

    <Button
        android:id="@+id/play_song"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginEnd="32dp"
        android:text="Play"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <Button
        android:id="@+id/delete_song"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginStart="28dp"
        android:text="Delete"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>

And drawable round_corners.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/gray_text"/>
    <stroke android:width="3dp" android:color="@color/colorBlack" />
    <corners android:radius="20dp"/>
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

And this is the result I get:

enter image description here

How can I remove the white corners?

kataroty
  • 719
  • 6
  • 27

1 Answers1

5

Just add the below mentioned line of code. it will set a transparent background to your dialog.

MyDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Anisuzzaman Babla
  • 4,563
  • 3
  • 25
  • 50