0

I want to get the displayable height of an activity. But, the display height I get from following snippet also include status bar height.

int screenHeight = context.getResources().getDisplayMetrics().heightPixels; 

What I want is the height starting from bottom edge of status bar or top edge of the screen to the top edge of bottom navigation bar (like, Nexus 4) or bottom edge of the screen (like, Samsung Galaxy S4). So what I do is I get the height pixels from above snippet and then deduct the status bar height

int screenHeight = ![context.getResources().getDisplayMetrics().heightPixels][1]; int statusBarHeight = 0; int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = context.getResources().getDimensionPixelSize(resourceId); } int displayableHeight = screenHeight - statusBarHeight; 

This snippet only works correctly on phone and 7" tablet. But on 10" tablet (which I don't see status bar anywhere on screen), the statusBarHeight snippet return 50px. Which cause the displayableHeight 50px less than what user see on the screen.

Do you know why on 10" Tablet report status bar height = 50px since is not showing on screen and How can I fix this issue?

Best

enter image description here

1 Answer 1

1

You're getting the dimension, not its actual height of the view, of course it wouldn't be reset when its hidden. You need to get the System Decor and derive your values from that.

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

2 Comments

Thanks for your comment, however, I call "getWindow().getDecorView().getHeight()" in the Activity's onCreate method after setContentView, it return 0 ... do you know why? or that's not what I suppose to call?
Because dimensions aren't calculated in the onCreate... might be onresume when views actually get their dimensions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.