Get the correct screen display size on Galaxy S8
Asked Answered
B

2

8

In my app I am currently using windowManager.getDefaultDisplay() to determine the screen size.

With the new Samsung S8 navigation bar, that can be shown and hidden using a 'dot' on the bottom left, I get the same display size for navigation bar shown or hidden. It always returns the display size as if the navigation bar is shown - I expect to get 1080x2220 when the navigation bar is hidden, but always gets 1080x2076.

Is there any way I can distinguish the cases programmatically and obtain the correct screen dimensions so I can display my app correctly?

Brelje answered 13/9, 2017 at 16:37 Comment(2)
I'm not too familiar with the situation, but is there a way to get the nav bar (e.g. getNavigationBar()) and check if isVisible() or not? If so, can you get the height of the navbar and add it to the screen? Or is the navbar area "restricted" in some way regardless of visibility?Tomboy
Have you tried to use the Immersive Full-Screen Mode?Dorrie
V
2

I had the same problem as you, and the solution I found was to measure the height of the content root view :

findViewById(android.R.id.content).getHeight()

hope it will help you.

check here for more detailes about android.R.id.content

Value answered 27/9, 2017 at 6:2 Comment(0)
A
1

I also had the same problem but the solution with the content root view didn't work for me (the height i got was 2148).

But i could solve this with the decorview:

    //Get the correct screen size even if the device has a hideable navigation bar (e.g. the Samsung Galaxy S8)
    View decorView = getWindow().getDecorView(); //if you use this in a fragment, use getActivity before getWindow()
    Rect r = new Rect();
    decorView.getWindowVisibleDisplayFrame(r);
int screenHeight = r.bottom; // =2220 on S8 with hidden NavBar and =2076 with enabled NavBar
int screenWidth = r.right; // =1080 on S8
Anthropolatry answered 19/6, 2018 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.