我如何禁用景观模式的一些观点在我的Android应用程序?


当前回答

在阅读这篇文章之前,我不知道AndroidManifest.xml文件开关,所以在我的应用程序中,我使用了这个代替:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Fixed portrait orientation

其他回答

在你的manifest中添加android:screenOrientation="portrait"。如果您想为特定的活动应用模式,请在所需的活动标记中定义此模式。或者在应用程序标签中定义整个应用程序。比如:

<application
    <!-- ... -->
    android:screenOrientation="portrait"
</application>

在<apphome>/platform/android目录下,创建AndroidManifest.xml(从生成的目录中复制它)。

然后添加android:screenOrientation="portrait"到所有的活动元素。

在Kotlin中,同样可以使用下面的代码以编程方式实现:

requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

在你声明你的活动的manifest文件中添加android:screenOrientation="portrait"。是这样的:

<activity 
    android:name=".yourActivity"
    ....
    android:screenOrientation="portrait" />

如果你想使用Java代码,试试:

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

在onCreate()中调用setContentView方法之前。

您必须设置每个活动的方向。

<activity
    android:name="com.example.SplashScreen2"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
    android:name="com.example.Registration"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
    android:name="com.example.Verification"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
    android:name="com.example.WelcomeAlmostDone"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
    android:name="com.example.PasswordRegistration"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>