问题
There are some devices such as Huawei p20(running android 8,8.1) which has in-built notch
on the top.
The current way to get the size of the screen is
Display display = getWindow().getWindowManager().getDefaultDisplay();
Point screenSize = new Point();
display.getRealSize(screenSize);
//screenSize.x
//screenSize.y
And it's leading the game out of screen. So, is there any way to solve notch issue with android P and Pre-p devices.
回答1:
There are only few android devices with notch
options and currently it is not possible to get exact screen size of such devices using Android APIs.
BUT there is a work around, you can check the name of device and adjust your layout accordingly.
There is one popular Android library to get the market name of an Android device. Check more information here : https://github.com/jaredrummler/AndroidDeviceNames
How to use this lib:
String deviceName = DeviceName.getDeviceName();
Hope this will help you to focus on your development instead of wasting time!
回答2:
The status bar(where all your notifications are) always adjusts to the depth of the notch. Look at the pixel 3 which has the largest notch in the world :p The status bar becomes as tall as the notch.
So the notch is only a problem if your app is in a full screen(content draws underneath the status bar) and it may cover some of your content. Make your app non-full screen (only draw below the status bar) and you don't have to worry about any notch size in the future. A lot of games ignore the status bar from their content.
来源:https://stackoverflow.com/questions/50482390/how-can-we-get-the-size-of-screen-with-notch-on-the-top