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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Is it in dp? or px?
-2

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

and you can also get the status height programmatically.

2 Comments

I get error AAPT: error: resource android:dimen/status_bar_height is private.
try to get it programmatically

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.