对话框-更改状态栏颜色

时间:2018-10-05 12:46:46

标签: android android-fragments android-theme android-dialog android-statusbar

我正在尝试创建并显示全屏对话框。我想使用此自定义对话框布局创建一些动画。这段代码适用于片段而不是活动。

我的代码如下:

            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();

下面的屏幕截图:

enter image description here

对话后。显示状态栏颜色更改。 enter image description here

R.style.Theme_AppCompat_Light对我不起作用。它将状态栏更改为浅灰色:)

如何显示完整的透明自定义对话框?

1 个答案:

答案 0 :(得分: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);