5

I have a full screen activity in my application. I want my page title to be positioned under status bar. How can I measure status bar height in a full screen activity?

I researched about it and tried them. One of them is this, which is using an attribute in xml that doen't work in my case. The other one is Second Solution

    val rectangle = Rect()

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

statusBarHeight is 0, because it's a full screen activity probably. Any help to position my some elements like title below status bar staff?

salmanseifian
  • 1,082
  • 3
  • 9
  • 26

2 Answers2

10

I found the answer finally :))

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

     val statusBarHeight = resources.getDimensionPixelSize(statusBarHeightId)

statusBarHeight is what I want.

salmanseifian
  • 1,082
  • 3
  • 9
  • 26
-1

Try android:layout_marginTop="@android:dimen/status_bar_height"

and you can also get the status height programmatically.

ADM
  • 20,406
  • 11
  • 52
  • 83
Amit pandey
  • 1,149
  • 1
  • 4
  • 15