2

I am trying to create and show a fullscreen dialog. I want to create some animation using this custom dialog layout. This code works on a fragment not activity.

My code is below :

            Dialog dialog = new Dialog(getContext());
            LinearLayout linearLayout = new LinearLayout(getContext());
            linearLayout.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
            linearLayout.setBackgroundColor(Color.TRANSPARENT);

            dialog.requestWindowFeature(1);
            dialog.setContentView(linearLayout);
            Window dialogWindow = dialog.getWindow();
            dialogWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            dialogWindow.setDimAmount(0.0f);
            dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
            // View.WindowManager.LayoutParams.MATCH_PARENT
            dialogWindow.setLayout(-1, -1);

            dialog.show();

The screenshots are below:

enter image description here

After dialog.show status bar color changes. enter image description here

R.style.Theme_AppCompat_Light doesn't work for me. It changes status bar as light gray :)

How can I show a full transparent custom dialog?

Saad
  • 28
  • 4
us2956
  • 476
  • 12
  • 27
  • Test case remove `dialogWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);` – AskNilesh Oct 05 '18 at 12:53
  • 1
    and use this **`dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);`** – AskNilesh Oct 05 '18 at 13:01
  • https://stackoverflow.com/questions/10795078/dialog-with-transparent-background-in-android – AskNilesh Oct 05 '18 at 13:01
  • 1
    @NileshRathod This setting is not enough. I use Theme_Holo_Light_NoActionBar_Fullscreen theme, but it removes icons in status bar. :/ – us2956 Oct 05 '18 at 13:36

1 Answers1

0
    Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(layout_file);
    dialog.getWindow().setLayout(AppBarLayout.LayoutParams.FILL_PARENT, AppBarLayout.LayoutParams.WRAP_CONTENT);
Arwy Shelke
  • 333
  • 1
  • 2
  • 12
  • I want to use full screen dialog. But this is not. – us2956 Oct 05 '18 at 13:34
  • Use RelativeLayout and modify last line of my code as below-- dialog.getWindow().setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); – Arwy Shelke Oct 05 '18 at 13:47