Ola Melén
Ola Melén

Reputation: 455

How do I know if there is a navigation bar?

The navigation bar is drawn on top of my activity with transparency so that my content can be seen through the navigation bar. This is fine and I want to have it like this. However, there are two types of devices:

  1. Devices with a transparent navigation bar
  2. Devices with a hardware navigation bar (like some Samsung models) in which the content, of course, is not drawn behind the navigation bar.

How do I know that the device my app is running on is of type 1 above? I.e. how can I programmatically get the answer to "is there a semi-transparent navigation bar put on top of my activity?"

Upvotes: 1

Views: 107

Answers (1)

gabriel
gabriel

Reputation: 2359

You can try something like:

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
}

Upvotes: 1

Related Questions