0

I want to shadow of my dialog fragment

We use this code for the dialog -

        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(root);
        if (dialog.getWindow() != null) {
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.getWindow().setLayout(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }```
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Aakash Yadav
  • 53
  • 1
  • 1
  • 6
  • you can design your (root) custom dialog using CardView which provide CardElevation for shadow effect and also easy way ;) – niceumang Jul 05 '19 at 07:17

1 Answers1

0

You can create a custom dialog class with custom layout, in your layout put cardView or any other view with shadow.

This will be your dialog class (or something similar, it's only an example):

public class FullSizeImageDialog extends Dialog {
private ImageView imageView;
private ProgressBar fullImageProgreesBar;
private Context dialogContext;

public FullSizeImageDialog(@NonNull Context context) {
    super(context);
    setContentView(R.layout.full_size_image_dialog);
    dialogContext = context;
    imageView = findViewById(R.id.full_size_image);
    fullImageProgreesBar = findViewById(R.id.fullImageProgreesBar);
    }
}

And this is your layout for the dialog (R.id.full_size_image in my case):

<?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"
  android:layout_width="match_parent"
  android:layout_height="match_parent">


 <!--Place your views here-->


 </android.support.constraint.ConstraintLayout>

Now all left to do is either use card view or check this thread talking about shadows on views.

And when you want to show your dialog it's super easy:

FullSizeImageDialog dialog = new FullSizeImageDialog ();
dialog.show();
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53