3

我目前正在为 Android 开发一个 OpenGL 应用程序。到目前为止一切正常,但导航栏有点令人不安......

有没有办法找出导航栏在横向时是像我的银河系一样在右侧,还是像在平板电脑上一样在底部。另外我需要导航栏的高度和宽度。

有谁知道我怎么能做到这一点?

谢谢

4

3 回答 3

1

我找到了解决我的问题的方法:

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

在这部分代码之后,width和height包含了没有导航栏或通知栏的高度和宽度。

于 2012-08-26T18:05:09.100 回答
1

我是这样做的:

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

//如果没有菜单键则有导航栏

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
            }

        }
于 2014-08-26T10:38:47.127 回答
1

在这里发帖是为了那些最终在这里寻找优雅处理导航栏和状态栏的方法的人的利益。

参考这篇文章

正如许多类似问题所建议的那样,例如thisthisthisthis,仅获取导航栏高度可能还不够。我们需要考虑1. 导航栏是否存在, 2. 是在底部,还是在右侧或左侧, 3. 应用程序是否以多窗口模式打开。

有一个简单的单行解决方案

android:fitsSystemWindows="true"

或以编程方式

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

您还可以通过以下方式获得根视图

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

有关获取根视图的更多详细信息,请参阅 - https://stackoverflow.com/a/4488149/9640177

于 2020-03-07T07:23:41.627 回答