rememberSystemUiController 获取状态栏高度
时间: 2024-04-24 19:22:58 浏览: 132
想获取状态栏的高度,你可以使用以下代码:
```kotlin
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
val statusBarHeight = if (resourceId > 0) {
resources.getDimensionPixelSize(resourceId)
} else {
0
}
```
其中,`resourceId` 是通过资源名称 `"status_bar_height"` 和资源类型 `"dimen"` 在系统资源中查找得到的标识符。如果找到了对应的资源,就可以使用 `resources.getDimensionPixelSize()` 方法来获取状态栏的高度;如果没有找到对应资源,就将状态栏高度设置为 0。
阅读全文
相关推荐















