我在一个片段上使用条形码扫描仪,我只需要旋转该片段即可扫描条形码。我在单个活动中尝试通过OnDestinationChangedListener进行轮换,但这似乎太昂贵了。我怎样才能更好地做到这一点?
答案 0 :(得分:1)
是的,当您导航到这样的片段时,您可以简单地应用“片段标志”
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activity?.let {
it.window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
it.window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
答案 1 :(得分:0)