I want to get real resolution of screen on Android Honeycomb.
Here's my code
Display display = getWindowManager().getDefaultDisplay();
int w = display.getWidth();
int h = display.getHeight();
My device is Asus Transformer TF101 with size are 1280x800.
But above code make w = 1280 and h = 752 (That i want is 800 not 752).
I know h < 800 because it's subtracted for status bar.
Have any way to get real height of screen?
Many thanks!
The answer you are getting, as properly deduced is because of the status bar. All you have to do is get rid of the status bar before your window display initiates. And then you can reset the status bar before you set the content view of the activity.
The reason to do it this way is that getting rid of the status bar affects your view drawing unless you handle all measure, layout and draw dynamically. Doing this is the middle of your runtime will cause the status bar to disappear, and then reappear if you want it to, resulting in confusion from users.
To Hide the StatusBar:
In your onCreate():
Now your Default Display should work correctly
Still in your onCreate():
Now before you set the Content
Again, in your onCreate():
Finally:
The previous code segments will work almost anywhere, actually. I'm just thinking about your user experience. Feel free to place them whereever, of course. These are functional segments pulled from one of my projects. I've seen techniques similar in some Home Launchers as well. Note: depending on the Android version, you might have to do the status bar stuff in onWindowAttached(). If you do, make sure you still call super.onWindowAttached().
Another Technique: Of course, if you want to do this anyway, you could always set the attribute of the activity this way in your manifest.
Starting Andorid 3.2, the height of system status bar is not included in DisplayMetrics's height, you have to use undocumented APIs (Display.getRawWidth() and Display.getRawHeight()) to get the physical screen width or height.
Here is the example to show you how to get the physical screen width or height.
UPDATED: For API 13-16, you have to use the above code to get real width/height. For API 17+, you can now use the new public API, Display.getRealSize().
A function to get the screen size at API11 level minimum; also includes methods for higher level APIs (change function to use the selected API, its function call and its return object type):
Note: Configuration.ORIENTATION_SQUARE is deprecated, so here it is replaced to default to ORIENTATION_PORTRAIT.
Here you are, with little trick and assumption that screen decorations are on top/bottom and never on left/right:
In the question Height of statusbar? explain how you get the statusbar height. Having the
statusBarHeight
value, you can do:Perhaps you can add the height of the status bar. Height of statusbar?