Custom dialog

Asked

Viewed 414 times

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>

3 answers

2

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

xml embroidery.

<?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 attribute android:background of your RelativeLayout. See below:

my_dialog.xml

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

    <!-- conteúdo -->

</RelativeLayout>

0

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

<corners
     android:radius="6dp"/>

0

Thank you so much for your help:

dialogPay.getWindow().setBackgroundDrawable(
    new ColorDrawable(android.graphics.Color.TRANSPARENT));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.