在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中有没有回调来听这个轮换?或者有更好的方法来了解导航栏的屏幕哪一侧,而不会遇到这个问题?
答案 0 :(得分:0)
您可以覆盖Activity#onConfigurationChanged(Configuration newConfig)以在用户旋转设备时获得回调。
您可以查看以下链接以获取更多详细信息: