全屏活动中的状态栏高度

问题描述 投票:0回答:2

我在我的应用程序中进行了全屏活动。我希望页面标题位于状态栏下。如何在全屏活动中测量状态栏的高度?

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

    val rectangle = Rect()

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

statusBarHeight为0,因为它可能是全屏活动。将我的某些元素(例如标题)放在状态栏人员下方是否有帮助?

android margin statusbar
2个回答
0
投票

尝试android:layout_marginTop="@android:dimen/status_bar_height"

您还可以通过编程方式获得status height


0
投票

我终于找到了答案:))

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

     val statusBarHeight = resources.getDimensionPixelSize(statusBarHeightId)

statusBarHeight是我想要的。

© www.soinside.com 2019 - 2024. All rights reserved.