Skip to content Skip to sidebar Skip to footer

Android Custom Alert Dialog With Rounded Corners And Transparent Background

I have created a custom AlertDialog with rounded corners using onDraw of LinearLayout as below, public class RoundedLinearLayout extends LinearLayout { private Paint drawPaint; pr

Solution 1:

I use this and it worked for me:

ConfirmacionMensaje customDialog = new ConfirmacionMensaje(MainActivity.this);
customDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
customDialog.show();

ConfirmacionMensaje exntends from Dialog

and this is my xml for Dialog:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="#ffDB0000"/>
<corners
    android:bottomLeftRadius="4dp"
    android:bottomRightRadius="4dp"
    android:topLeftRadius="4dp"
    android:topRightRadius="4dp" />
</shape>

Solution 2:

Do use alert dialog use simple dialog

 LayoutInflater  factory = LayoutInflater.from(getActivity());
            AlertDialog alert = new AlertDialog.Builder(getActivity());

        Dialog  dialog = new Dialog(getActivity());

            dialog.setContentView(your layout);

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

Solution 3:

Use this :

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

It is the simplest solution and it works.


Solution 4:

This worked for me

dialog.getWindow().setBackgroundDrawable(getResources().getDrawable(R.drawable.background_verification));

background verification is my drawable file


Solution 5:

This can be solved:

   dialog.getWindow().setBackgroundDrawable(getResources().getDrawable(R.drawable.background_verification));

Post a Comment for "Android Custom Alert Dialog With Rounded Corners And Transparent Background"