Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding round corners to Android Layout leaves white edges [duplicate]

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?

like image 911
Richard Avatar asked Aug 15 '18 22:08

Richard


People also ask

How do I round corners in Android?

xml file and add an attribute to that TextView, for which you want to add rounded corners. The attribute is android: background=”@drawable/rounded_corner_view”.

How do you make a rounded rectangle on Android?

Use CardView for Round Rectangle. CardView give more functionality like cardCornerRadius, cardBackgroundColor, cardElevation & many more. CardView make UI more suitable then Custom Round Rectangle drawable.


1 Answers

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));
like image 55
Anisuzzaman Babla Avatar answered Sep 26 '22 14:09

Anisuzzaman Babla