Usually when using Accompanist Modifier.statusBarsHeight() the height will change depends on the status bar visibility, if it's visible either 24.dp or more and if it's invisible the height will be 0.dp. But i want the height won't change to zero regardless of its visibility.
I've been using this for a while:
// TODO: use better solution to get a fixed status bar height
val statusBarHeight = with (LocalDensity.current) { LocalWindowInsets.current.statusBars.top.toDp() }
val fixedStatusBarHeight = remember { statusBarHeight }
The problem is getting complicated you should use it like this
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Box(
modifier = Modifier
.fillMaxSize()
.statusBarsPadding().navigationBarsPadding()
) {
}
Box(
modifier = Modifier
.fillMaxSize()
.statusBarsPadding().systemBarsPadding()
) {
}
}
}
}
You can use WindowInsets.statusBars.getTop(this)
For example (map takes all screen - behind status and navigation bar):
GoogleMap(
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState,
properties = MapProperties(isMyLocationEnabled = true),
contentPadding = with(LocalDensity.current) {
PaddingValues(
top = WindowInsets.statusBars.getTop(this).toDp(),
bottom = WindowInsets.navigationBars.getBottom(this).toDp()
)
}
) {
Result:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With