分享

Android Dialog 状态栏颜色变黑问题处理

 狄伦视角 2021-06-18

当Dialog 布局设置满屏的情况下状态栏颜色透明的代码失效了,

       WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();

        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;

        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;

解决方式:窗口高度=用屏幕高度减去状态栏高度


        WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();

        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;

        layoutParams.height =ScreenUtils.getScreenHeight(context)-ScreenUtils.getStatusBarHeight(ContextUtils.getActivity(context));

        layoutParams.gravity=Gravity.BOTTOM;


另外就是Dialog 弹出来的时候如何使Dialog 的状态栏和它的宿主Activity的状态栏保持一致呢?

DialogUtils.keepStatusBarSameStyleWithActivity(this);

//

keepStatusBarSameStyleWithActivity(Dialog dialog){
    (dialog.getWindow()!=)dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)}

这个方法会使Dialog背景色透明


对话框布局弹出来的时候会抖动?

当xml布局内容设置了MATCH_PARENT, 那么我们需要在Dialog 的构造器中设置窗口的大小,

去掉在show() 方法里面的宽高设置,移到构造器中来实现。



    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多