Check for Navigation Bar

Check for navigation bar

Took me some time but I've found a more reliable way than relying on hasPermanentMenuKey() which doesn't work for newer phones like the HTC One which have no menu key but do have home & back keys so don't need (or show) the soft navigation bar. To get around this try the following code which checks for a back button too:

boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

if(!hasMenuKey && !hasBackKey) {
// Do whatever you need to do, this device has a navigation bar
}

How to detect bottom soft navigation bar available in android programmatically?

Following method worked for me and tested in many devices.

public boolean hasNavBar (Resources resources)
{
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
return id > 0 && resources.getBoolean(id);
}

Note: Verified this method in real device

iOS - Check for Navigation bar

UINavigationBar inherits from and has all the fine properties and behaviors of UIView and one of these properties is hidden.

So for your view, if you can get a handle to your navigation bar, all you need to do is check to see if hidden is YES or NO.


one way to do this would be to have a UINavigationController property or accessor (setter & getter) for your library so whoever makes use of the library can set the navigation controller and/or bar on your library's behalf.



Related Topics



Leave a reply



Submit