Search code examples
androidandroid-jetpack-composedensity-independent-pixel

Android Compose set height of view in pixels NOT in dp


I want to set the height of view in pixels not in dp.

 `Box(modifier = Modifier.height(100.dp))`

In this example height of the box is set to 100 dp and modifier function accepts only dp. How to set height of Box in pixel?


Solution

  • @Kilian it right, this can look like this:

    Modifier.height(with(LocalDensity.current) { 100.toDp() })