4
Dialog(
  properties = DialogProperties(usePlatformDefaultWidth = false),
  onDismissRequest = {viewModel.showDialog.value = false}
){
  Column(modifier = Modifier.width(LocalConfiguration.current.screenWidthDp.dp)
    .height(LocalConfiguration.current.screenHeightDp.dp).background(color = Color.Black.copy(alpha = 1f))) {

  }
}

Running this code results in a dialog with fullscreen, but the height does not fully match the screen height.

Is there any way to make the dialog take full width and height of the screen size?

Please find the screenshot below:

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
Ali_Waris
  • 1,944
  • 2
  • 28
  • 46
  • How were you able to remove the system navigation buttons when the modal comes up? I have this issue https://stackoverflow.com/questions/74465492/jetpack-compose-immersive-mode-dialog?noredirect=1#comment131465024_74465492 – HaMiD Sani Nov 21 '22 at 22:31

2 Answers2

4

If you take a took at how screenHeightDp is defined.

The current height of the available screen space, in dp units, corresponding to screen height resource qualifier.

Apparently, It excludes the area occupied by window insets, such as the status bar, navigation bar, and cutouts.

So here is a solution I managed to solve the problem. It try to get entire screen size from WindowManager. and feed them via Modifier.requiredSize(). Note that it is important to ignore parent constraints by using requiredSize, otherwise it won't work. More info at https://stackoverflow.com/a/65779227/157675 .

    Dialog(
        properties = DialogProperties(usePlatformDefaultWidth = false),
        onDismissRequest = onDismiss
    ) {
        val context = LocalContext.current
        val windowManager =
            remember { context.getSystemService(Context.WINDOW_SERVICE) as WindowManager }

        val metrics = DisplayMetrics().apply {
            windowManager.defaultDisplay.getRealMetrics(this)
        }
        val (width, height) = with(LocalDensity.current) {
            Pair(metrics.widthPixels.toDp(), metrics.heightPixels.toDp())
        }
        Column(
            modifier = Modifier
                .requiredSize(width, height)
                .background(color = Color.Green)
        ) {
           // ...
        }
    }
Gasol
  • 2,319
  • 17
  • 27
0

For making the dialog fill the full screen either use Modifier.fillMaxSize() or use Modifier.fillMaxWidth() along with Modifier.fillMaxHeight().

Chandresh Parmar
  • 176
  • 1
  • 10