3

Android seems to be cutting off the bottom 100px on devices that have virtual / on screen buttons. Is it possible to detect if the current phone / tablet is using on screen buttons so that I can account for the missing space? If so, is it possible to get the height of the buttons as well?

Xlythe
  • 127
  • 2
  • 9

2 Answers2

2

You can check if the device has a permanent (hardware) menu button by using hasPermanentMenuKey(). It can be used as following:

boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();

Notice that this technique will work only on APIs 14+ (ICS, JB). No device pre-API-11 has menu buttons, so that leaves only APIs 11-13 without a check; keep in mind that these 3 API levels have only 2.3% of the Android population currently.

Alternately (though not reliably), you could try searching for a D-Pad:

boolean hasDpad = getResources().getConfiguration().naviation == Configuration.NAVIGATION_DPAD;

There is no way to check for a hardware search button (and I would assume home/back as well), as seen here. (Also here; this thread proposes an alternative method, though I'm not sure it will work in your case.)

I will mention two things: The virtual buttons should NEVER be covering your content. They do subtract from the height of the device window (as fetched by the display's metrics), but they will never hinder your layout if you are using match_parent as a height. Second, there is no way to fetch the exact height of the virtual button bar; it may change between builds. There is also no native way in the Android API to fetch the "available" screen space (the area that is not covered by the bar at the bottom).

So, here is what I will suggest:

Community
  • 1
  • 1
Cat
  • 66,919
  • 24
  • 133
  • 141
  • Thanks! There doesn't seem to be anything I can do then. However, at least on the Nexus 7, the virtual buttons ARE covering my content, despite setting match_parent. The quickest test I could find is to fill a ScrollView with match_parent. The thin blue line that signifies you can't scroll further is cut off on the edge with buttons. (In my case, there's a draggable handle about the same height that disappears off the screen if I don't account for it). Hopefully I'm wrong, though, since I haven't tested without the handle logic. If it's something I did wrong, that's much easier to fix. – Xlythe Aug 20 '12 at 14:53
  • That's very odd; I don't have that issue on my Galaxy Nexus. Sadly I don't have a Nexus 7 to confirm it. Sorry I couldn't be more help! – Cat Aug 20 '12 at 16:21
  • PADDING! Oh god. Padding is what caused my issues. I... feel embarrassed now. But thank god it was my fault. – Xlythe Aug 20 '12 at 23:55
  • Agreed! Glad you got it fixed now! :) – Cat Aug 21 '12 at 01:36
0

From what I remember, the virtual buttons on the bottom are only in android versions 3.0 (Honeycomb) and above. As for the height issue, I've never really looked into it.

Jwc24678
  • 161
  • 1
  • 7