3

I'm currently developing an OpenGL app for Android. Everything works fine so far, but the navigation bar is a little bit disturbing...

Is there a way to find out if the navigation bar is on the right side like on my galaxy nexus when in landscape or if it is on the bottom like on tablets. In addition I need the height and width of the navigation bar.

Does anyone know how I can achieve this??

Thanks

Wroclai
  • 26,835
  • 7
  • 76
  • 67
glethien
  • 2,440
  • 2
  • 26
  • 36

3 Answers3

1

I found a solution for my problem:

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size); 
    width = size.x;
    height = size.y;

After this part of code, width and height are containing the height and the width without the navigation bar or notification bar.

glethien
  • 2,440
  • 2
  • 26
  • 36
1

I did it in this way:

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

//if there is not menu key then there is navigation bar

if (!hasMenuKey && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
         DisplayMetrics dm = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(dm);

            if (dm.heightPixels%10!=0) {
            //navigation bar is on bottom
            } else {
               //navigation bar is on right side
            }

        }
support_ms
  • 1,873
  • 1
  • 18
  • 33
  • and if you have a device whose height will be 768px when rotated? height%10 != 0 will return `true` but the navigation bar is on the right.. Have you found any more reliable solution to check the navigation bar position? – Droidman Mar 21 '15 at 16:06
  • On that time it was the only solution I found for more devices. However I still could not find good solution – support_ms Mar 23 '15 at 05:21
1

Posting here for benefit of those who end up here looking for ways to elegantly handle Navigationbar and Statusbar.

Refer this post.

As suggested in many of similar questions, for example this, this, this, and this, simply getting navigation bar height may not be enough. We need to consider whether 1. navigation bar exists, 2. is it on the bottom, or right or left, 3. is app open in multi-window mode.

There is a simple one line solution

android:fitsSystemWindows="true"

or programatically

findViewById(R.id.your_root_view).setFitsSystemWindows(true);

you may also get root view by

findViewById(android.R.id.content).getRootView();
or
getWindow().getDecorView().findViewById(android.R.id.content)

For more details on getting root-view refer - https://stackoverflow.com/a/4488149/9640177

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122