Custom Dialog

0

Good morning, I made a custom Dialog using a fragment to customize it, but I need to make it have rounded corners.     

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/shape_modal_dialog">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/title"
        style="@style/Title_white"
        android:text="Atenção"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="15dp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text"
        android:text="Você tem mais de 18 anos?"
        android:textColor="@color/white"
        android:layout_below="@+id/title"
        android:gravity="center"
        android:layout_marginBottom="34dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/button"
        android:weightSum="10"
        android:orientation="horizontal"
        android:layout_below="@+id/text">

        <TextView
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="5"
            android:id="@+id/btn_no"
            android:text="Não"
            android:clickable="true"
            android:textColor="@color/red"
            android:gravity="center"
            android:background="@drawable/button_effect_secondary_dialog"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="5"
            android:id="@+id/btn_yes"
            android:clickable="true"
            android:text="Sim"
            android:textColor="@color/white"
            android:gravity="center"
            android:background="@drawable/button_effect_primary_dialog" />

    </LinearLayout>

</RelativeLayout>
    
asked by anonymous 01.09.2016 / 13:52

3 answers

2

You can create a file in which you will define background . For examples borda_redonda.xml , placing it inside your drawable , remembering that each corner can be defined with different sizes. The borders are defined using <corners> proposing for each corner, a different size using Radius . To insert a background color use the parameter <solid> setting android:color being equal to the color in hexadecimal. In the example just below a black color with #E6 transparency was defined. See:

round border.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#E6000000" />
            <corners
                android:bottomRightRadius="10dp"
                android:bottomLeftRadius="10dp"
                android:topLeftRadius="10dp"
                android:topRightRadius="10dp" />
        </shape>
    </item>
</layer-list>

Then just set the android:background attribute of your RelativeLayout . See below:

my_dialogo.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/borda_redonda">

    <!-- conteúdo -->

</RelativeLayout>
    
01.09.2016 / 14:48
0

In your shape_modal_dialog file, you need to add the following field:

<corners
     android:radius="6dp"/>
    
01.09.2016 / 14:20
0

Many thanks for the help, I was able to solve this:

dialogPay.getWindow().setBackgroundDrawable(
    new ColorDrawable(android.graphics.Color.TRANSPARENT));
    
01.09.2016 / 20:54