Currently when I draw at 0,0 the status bar covers the drawing. Is there a way to adjust the position of the surface or do I need to build a draw offset in to account for status bar - effectively drawing everything starting at y=25?
-
2I found http://developer.android.com/reference/android/view/View.html#attr_android:fitsSystemWindows. Not sure whether is helpful. – André Oriani Aug 21 '12 at 01:19
-
Thanks, I did see this before posting, but it is for ICS and above - not very practical for current development. Upvote for the relevant input! – ajh158 Aug 21 '12 at 13:34
4 Answers
I'm not sure why the surfaceview overlaps the status bar (sounds like an android bug), but the easiest thing would probably be to use glViewport
to just define which area of the surfaceview you intend to use for drawing.
If you can figure out how high the status bar is, then just subtract that from the height of your glViewport call, and then all your calls will be mapped to just inside the viewport range.

- 35,413
- 11
- 95
- 121
-
I'd prefer to adjust the surface size somehow, but this answer certainly beats using a draw offset for every draw call! I'm going to give it a try right now. Thanks (still hoping for a different answer/explanation that addresses the Surface approach, but will accept in a few days if no one answers with something like that). – ajh158 Aug 21 '12 at 13:42
When I had this problem, I had a dummy View on top of the Surface ( I did that using a FrameLayout) that would be big as the ContentView . So all I need was to to call View.getLocationOnScreen(int[])
to know where I should start drawing.

- 3,553
- 22
- 29
-
Thanks for the suggestion - upvote for relevant input! If I have to handle this by adjusting my drawing somehow, it seems like calculating the status bar height would be the way to go, as described here: http://stackoverflow.com/questions/3355367/height-of-statusbar/3356263#3356263 – ajh158 Aug 21 '12 at 13:39
You may need to tell android which theme/style to use for your activity.
Include the following in your AndroidManifest.xml for the activity that creates the glSurfaceView:
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
Or if you want to keep the statusbar:
android:theme="@android:style/Theme.Black.NoTitleBar"
Here's more on themes and styles: http://developer.android.com/guide/topics/ui/themes.html
EDIT: This way android will (should) take the requested layout into account when creating the glSurfaceView, so there won't be any need for offsets...

- 804
- 1
- 8
- 18
-
Thanks for responding. I already have the second theme in my manifest. It would be nice if Android took the status bar into account, but it doesn't. That's the crux of the problem. – ajh158 Aug 22 '12 at 17:22
-
Oh ok,I see now... you want to keep the statusbar but the glsurface is created incorrectly so that the statusbar covers part of your surfaceview even when using the correct theme. hmm... – Erik Aug 22 '12 at 18:01