Android 8 - 如何知道从LANDSCAPE到REVERSE_LANDSCAPE时导航栏的哪一侧?

时间:2018-05-09 10:58:30

标签: android navigationbar android-8.0-oreo

在Android 8中,当手机转到LANDSCAPE时,导航将位于屏幕的右侧,当它位于REVERSE_LANDSCAPE时,它将位于左侧。 我所做的是找出屏幕的哪一侧是我的活动的根View,并以这些方式检查它的大小和位置:

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
}

但是我遇到了有关此方法的新问题,即如果用户直接从LANDSCAPE转到REVERSE_LANDSCAPE导航栏会改变位置,但代码不会运行再次导致问题。

android sdk中有没有回调来听这个轮换?或者有更好的方法来了解导航栏的屏幕哪一侧,而不会遇到这个问题?

1 个答案:

答案 0 :(得分:0)

您可以覆盖Activity#onConfigurationChanged(Configuration newConfig)以在用户旋转设备时获得回调。

您可以查看以下链接以获取更多详细信息: