android - 全屏 Activity 中的状态栏高度

标签 android margin statusbar

我的应用程序中有一个全屏 Activity 。我希望我的页面标题位于状态栏下方。如何测量全屏 Activity 中的状态栏高度?

我对此进行了研究并尝试了它们。其中之一是 this ,它在 xml 中使用了一个属性,但在我的情况下不起作用。另一个是Second Solution

    val rectangle = Rect()

    window.decorView.getWindowVisibleDisplayFrame(rectangle)
    val statusBarHeight = rectangle.top

statusBarHeight 为 0,因为它可能是全屏 Activity 。是否有助于将我的一些元素(如标题)放在状态栏员工下方?

最佳答案

我终于找到了答案:))

     val statusBarHeightId = resources.getIdentifier("status_bar_height", "dimen", "android")

     val statusBarHeight = resources.getDimensionPixelSize(statusBarHeightId)

statusBarHeight 是我想要的。

关于android - 全屏 Activity 中的状态栏高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60680407/

相关文章:

ios - 在 MailComposer 关闭后,StatusBar 位于 navigationBar 之上

android - onScroll()问题(执行了3次)

android - 设备处于 sleep 状态时定期通知是否有效

java - 对 CONTENT_FILTER_URI 结果进行排序

android - 在应用程序之间共享私有(private)持久数据的任何解决方案?

plot - 如何使用 matplotlib 以 mm/cm 为单位指定绘图的边距?

html - Tumblr 在帖子中添加不需要的填充?

html - 基于宽度而不是高度的垂直边距的 CSS %

objective-c - 如何在开始时检测 iPad 的 interfaceRotation?

c++ - 在 Win32 应用程序中添加状态栏