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?
Share
You can check if the device has a permanent (hardware) menu button by using
hasPermanentMenuKey(). It can be used as following: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:
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_parentas 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:
ViewGrouporLinearLayoutor something).onLayout()](http://developer.android.com/reference/android/widget/LinearLayout.html#onLayout(boolean, int, int, int, int)) oronMeasure(), and get your layout’s exact height from this. (You may want to use this for reference.)