I've previously used some of the solutions on this question to offset a PopUpWindow window directly underneath the status bar. This works fine on an S8+ (which reports a status bar height of 84 pixels) as long as the app has not been set as a "Full Screen App".
If the app has been set to be a "Full Screen App" under Settings -> Display -> Full Screen Apps, the PopUpWindow will not display directly beneath the (still visible) status bar. Although the system still reports a status bar height of 84 pixels, the correct offset at this point is 0.
I can work around this by calculating the aspect ratio of the screen and if it is 1.9388889, then the app is in full screen mode, so the PopUpWindow offset can be set to 0.
However, this feels fragile and I'm not sure how this will work on other devices that support tall aspect ratios (LG6, etc). Ideally I would have a way to detect if an app is running in full screen without relying on specific aspect ratios. This seemed ideal:
boolean fullScreen = (getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
...but it returns false on an S8+ running an app set to be a Full Screen App. It appears Full Screen Mode and Full Screen App are two distinct concepts.
Rather than using specific aspect ratios, is there a better way to detect something is running as a Full Screen App? Or, a more robust way to calculate the status bar offset required, that will handle this Full Screen App scenario?
Related
I have a C++ app that runs as the home app. I am testing on Android 5.0.2.
When I restart my app ANativeWindow_getHeight returns to me a height of 752. This is the screen height minus the nav bar at the bottom. This is the result even though the nav bar is not showing and the area of the window is indeed 800 pixels.
When I reboot the device and it launches my home app immediately, ANativeWindow_getHeight returns the actual window height of 800.
Is there anyway I can reliably get the actual window height in all scenarios?
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.
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.
There are only a few android devices with notch option and currently it is not possible to get the 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!
I have been working on this for days now. Looking through countless articles and trying a lot of different ideas that I have had.
All I am looking to do is have a background image or element that is 100% of the browser height.
The problem is that whenever the address bar shows and hides the available space changes and the picture resizes causing an annoying jump.
I am using a full screen image slider called maximage 2 (http://www.aaronvanderzwan.com/maximage/)
First I tried to make the html or body containers aligned to the top and 120% high so that when the address bar goes away it will still cover. But the image still resizes as 120% of the new size is still different.
I have also been trying to store the original browser height and then adding to that number to compensate for the address bar and resizing the slider to the new size.
I was thinking in the way of using device aspect ratios and taking into account something that stays fixed such as the width, but this would vary from device to device and not be reliable.
Does anyone know of any simple and clean ways to simply cover the background of a mobile device with an image slider without using a percentage that will resize?
I had the same problem. The solution was to set the background hight to window height via jQuery and block the resize event while the scroll event is active.
That way you can scroll let the address bar disappear and have no nasty resize jump happen.
https://stackoverflow.com/a/31546432/1612318
I am trying to get the available screen area of my app programmatically.
To do so I am using getWindowManager().getDefaultDisplay().getSize() . However I am not quite sure of what is exactly the screen area corresponding to this 'Default Display Window'.
It seems to incorporate the whole screen (including the notification bar) except the navigation bar. Is this correct ? Are there exceptions ?
From the documentation:
Gets the size of the display, in pixels.
Note that this value should not be used for computing layouts, since a
device will typically have screen decoration (such as a status bar)
along the edges of the display that reduce the amount of application
space available from the size returned here. Layouts should instead
use the window size.
The size is adjusted based on the current rotation of the display.
The size returned by this method does not necessarily represent the
actual raw size (native resolution) of the display. The returned size
may be adjusted to exclude certain system decoration elements that are
always visible. It may also be scaled to provide compatibility with
older applications that were originally designed for smaller displays.
Emphasis mine. So yes, it's possible they might exclude the navigation bar from it, but not necessarily.
Yes, it includes all space usable by your application (i.e., not counting OS level components like the status and notification bar).
However, the size does change based on whether use you methods such as setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); which hides the notification and status bar and gives your application temporarily more room.
I'm working with the Kindle Fire HD 8.9", and unlike other Android tablets, its navigation bar (Back, Home, etc.) resides on the right edge of the device rather than the bottom edge. This is causing layout issues for myself since I need to calculate sizes as a percentage of the available screen width.
I've tried Display#getPoint(Point), as the Javadoc wording makes it sound like it will exclude system decor, but it does not for this device. I'm also aware of setting a OnLayoutChangeListener on my root view, but I need to know the available size prior to when this listener is triggered.
So is there a way to get the size of the navigation bar programmatically? I've calculated the size to be 90px, but I want to avoid hardcoding as it's risk-prone.