How to leave a Alertdialog with rounded edges?

Asked

Viewed 872 times

3

When I want to make a Dialog customized I just put one layout inside it. But around it Dialog is square, someone knows how to round?

2 answers

3

Follow an example:

Java:

Dialog  dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setContentView(R.layout.dialog_layout);

dialog_layout.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded_box"
    android:layout_gravity="center”>

</RelativeLayout>

drawable/rounded_box.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color=“#FFFFFF" />
    <corners android:radius=“5dp" />
</shape>

0

I believe that changing the theme can help you, only you will need to manually configure some size information of your alertDialog, arrange a layout to be the basis in your xml, and inside it Centralize what you want in the size you want, and in your code where you create the alertDialog theme Builder as parameter:

new AlertDialog.Builder(context, android.R.style.Theme_Translucent_NoTitleBar);

Note that this will make your Lert dialog transparent, to make the corners rounded just put an image with rounded corners and that has transparency and finally set as the background of your layout.

Browser other questions tagged

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