我现在正在开发一个Android应用程序,这只是为了演示目的。因此,在项目开发过程中,我们并未将重点放在应用程序的方向更改上。只要方向发生变化,应用程序就会崩溃。现在为每个活动或片段维护数据为时已晚。
所以我的问题是,有没有办法在整个应用程序中设置potrait的方向。即使用户旋转手机,我们能否保持状态为potrait?
答案 0 :(得分:2)
TL; TR:将其添加到AndroidManifest.xml
<activity android:name=".YourActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"/>
您也可以结帐this。
答案 1 :(得分:1)
来自Java:
@Override
public void onCreate(Bundle
savedInstanceState){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
来自XML:
<activity
android:name=".ActivityName"
android:label="@string/app_name"
android:screenOrientation="portrait" />