简体   繁体   English

锁定屏幕方向不是永久的(android:screenOrientation =“纵向”)

[英]Locking screen orientation isn't permanent (android:screenOrientation=“portrait”)

Let's say Activity A has portrait set in manifest, and Activity B has unspecified in manifest. 假设活动A在清单中设置了肖像,活动B在清单中未指定。 It seems that once I used setRequestedOrientation in Activity B, then popping the back stack to Activity A has activity A in landscape. 看来,一旦我在活动B中使用了setRequestedOrientation,然后将回栈弹出到活动A中,活动A就处于横向状态。 Is this expected behavior? 这是预期的行为吗? Does that mean that setRequestedOrientation would possibly change behavior of what's specified in AndroidManifest? 这是否意味着setRequestedOrientation可能会更改AndroidManifest中指定的行为?

If you're manually modifying the orientation using setRequestedOrientation in Activity B, I think you need to manually handle the orientation in Activity A. 如果您要在活动B中使用setRequestedOrientation手动修改方向,我认为您需要在活动A中手动处理方向。

You can force an activity to always be one orientation by putting: 您可以通过输入以下内容来强制一项活动始终是一个方向:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Right above your setContentView call. 就在您的setContentView调用上方。

As answerd before you should use 按照回答,您应该使用之前

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

If you want all your activities to be, let's say, Portrait, create an abstract Base Activity and extend it in all your activities 如果您希望所有活动成为肖像,则可以创建一个抽象的基本活动并将其扩展到所有活动中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM