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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With