Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for navigation bar

I am trying to check to see whether the android navigation bar is present on load so that I can adjust a layout accordingly, does anyone have any suggestions?

This is the navigation bar I am trying to detect: enter image description here

P.S. All I have found so far are 'bad' ways to try and remove the bar, which I dont want to do.

like image 203
Jonno Avatar asked Apr 18 '13 20:04

Jonno


People also ask

How do I turn on the navigation bar?

From Settings, tap Display, and then tap Navigation bar. Make sure Buttons is selected, and then you can choose your desired button setup at the bottom of the screen. Note: This option will also affect the location you swipe when using Swipe gestures.

Where is the navigation toolbar located?

Located along the side of the screen, the Navigation Pane provides a quick way to access the objects in Microsoft Access. You can hide or show the Navigation Pane at any time.

Where is the navigation bar on Iphone?

According to Apple documentation, "An iOS Navigation bar appears at the top of an app screen, below the status bar, and enables navigation through a series of hierarchical app screens.


2 Answers

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 } 
like image 51
philask Avatar answered Sep 20 '22 09:09

philask


There's no reliable way to check for a navigation bar. Using KeyCharacterMap.deviceHasKey you can check if certain physical keys are present on the device, but this information is not very useful since devices with physical keys can still have a navigation bar. Devices like the OnePlus One, or any device running a custom rom, have an option in the settings that disables the physical keys, and adds a navigation bar. There's no way to check if this option is enabled, and deviceHasKey still returns true for the keys that are disabled by this option.

This is the closest you can get:

boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);  if (hasBackKey && hasHomeKey) {     // no navigation bar, unless it is enabled in the settings } else {     // 99% sure there's a navigation bar } 

If the back and home button are not both physically present on the device, it must have a navigation bar, because the user otherwise wouldn't be able to navigate at all. However, you can never be 100% sure about this, since manufacturers can implement deviceHasKey wrong.

like image 34
Rudey Avatar answered Sep 20 '22 09:09

Rudey