我如何禁用景观模式的一些观点在我的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>
推荐文章
- android:在触摸移动时移动视图
- 如何以编程方式将ID分配给视图?
- 如何解决INSTALL_FAILED_DEXOPT错误?
- 有没有办法自动安装Android SDK ?
- 如何检查一个视图在Android中是否可见?
- Android是否保留。apk文件?如果有,在哪里?
- 在Android 5棒棒糖中,通知栏图标变成白色
- 从URI获取真实路径,Android奇巧新的存储访问框架
- 如何检查JSON键是否存在?
- ImageView -有高度匹配宽度?
- 如何确定在android文件的MIME类型?
- 这是在Android中获取用户位置的好方法
- Android从左到右幻灯片动画
- 如何检索视图的维度?
- 如何改变菜单项的文本颜色在安卓?