Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓8-当从横向到反向时,如何知道导航栏在哪一边?_Android_Navigationbar_Android 8.0 Oreo - Fatal编程技术网

Android 安卓8-当从横向到反向时,如何知道导航栏在哪一边?

Android 安卓8-当从横向到反向时,如何知道导航栏在哪一边?,android,navigationbar,android-8.0-oreo,Android,Navigationbar,Android 8.0 Oreo,在Android 8中,当手机进入横向时,导航将位于屏幕右侧,当手机进入反向_横向时,导航将位于左侧。 为了找出它在屏幕的哪一侧,我做的是让我的活动的根视图,并通过以下方式检查它的大小和位置: if (rootView.width == deviceScreenWidth) { // device is tablet and the navigation bar is at the bottom, or // its a samsung device with no naviga

在Android 8中,当手机进入
横向
时,导航将位于屏幕右侧,当手机进入
反向_横向
时,导航将位于左侧。 为了找出它在屏幕的哪一侧,我做的是让我的活动的根
视图
,并通过以下方式检查它的大小和位置:

if (rootView.width == deviceScreenWidth) {
    // device is tablet and the navigation bar is at the bottom, or
    // its a samsung device with no navigation bar
} 
else if (rootView.positionOnScreenX == 0) {
    // the navigation bar is at the LEFT side
} 
else {
    // the navigation bar is at the RIGHT side
}
但是关于这种方法,我面临着一个新的问题,即如果用户直接从
横向
转到
反向_横向
导航栏将改变位置,但代码不会再次运行,这会导致问题

android sdk中是否有任何回调来侦听此轮换?或者,有没有更好的方法可以知道导航栏位于屏幕的哪一侧,而不会遇到此问题?

您可以覆盖Activity#OnConfiguration Changed(Configuration newConfig),以便在用户旋转设备时获得回调

您可以签出这些链接以了解更多详细信息:


现在这不是一个真正的答案。导航可以在左侧或右侧。在左侧带充电器的Nexus 5x上。。。导航在左边。在像素2上,当充电器位于左侧时,导航位于右侧。您曾经在@simmorsal解决过这个问题吗?我面临着完全相同的问题。如果你想在一个活动中做这件事,那么你可以阅读插图,但是如果你(像我一样)在一个服务中做这件事,那就行不通了。@JamesCarlyle Clarke不幸的是没有。我最终重新设计了我想做的事!明白,谢谢@simmorsal回复我。