我目前正在为Android开发一个OpenGL应用程序。到目前为止一切都很好,但导航栏有点儿干扰...
是否有一种方法可以找出导航栏是否像我的Galaxy Nexus在横屏时在右侧,还是像平板电脑一样在底部。 此外,我需要导航栏的高度和宽度。
有谁知道我怎么能实现这个??
谢谢
我目前正在为Android开发一个OpenGL应用程序。到目前为止一切都很好,但导航栏有点儿干扰...
是否有一种方法可以找出导航栏是否像我的Galaxy Nexus在横屏时在右侧,还是像平板电脑一样在底部。 此外,我需要导航栏的高度和宽度。
有谁知道我怎么能实现这个??
谢谢
为了使导航栏和状态栏的处理更加优雅,我在这里发布帖子,以便那些寻找解决方法的人受益。
请参考this post。
正如许多类似问题所建议的,例如this, this, this, 和 this,仅仅获取导航栏高度可能是不够的。我们需要考虑以下几点: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://dev59.com/Ym855IYBdhLWcg3wMBPV#4488149
我找到了解决我的问题的方法:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
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
}
}
height%10 != 0
将返回true
,但导航栏位于右侧... 您是否找到了更可靠的解决方案来检查导航栏位置? - Droidman