即使禁用它,活动的方向仍然在变化
Orientation of activities still changing even after disabling it
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Fantasy">
<activity
android:name="view.StandingsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.RegisterActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.PlayerStandingsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.ScheduleActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="view.MatchStatsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.PlayerDetailsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.PlayerStatsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.AwardsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.TeamActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.AddPlayersActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
</application>
这是我的清单文件的一部分。我已指定禁用横向模式,但旋转屏幕时方向仍然会发生变化。我错过了什么?我必须在此处添加任何权限吗?
您可以重写每个 activity 的 onConfigurationChanged 方法以自行处理方向更改。否则在您的清单文件中声明 android:configChanges 您根本无法处理它们。
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo."orientation type your preffer");
}
当 android:screenOrientation="portrait" or "landscape"
在 manifest
文件中设置时,如果您想这样做,仍然不会触发任何侦听器,请尝试以编程方式在您的 onConfigurationChanged()
中处理仅纵向模式,在这里您将也可以再次启动 activity。
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Fantasy">
<activity
android:name="view.StandingsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.RegisterActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.PlayerStandingsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.ScheduleActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="view.MatchStatsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.PlayerDetailsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.PlayerStatsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.AwardsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.TeamActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity
android:name="view.AddPlayersActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
</application>
这是我的清单文件的一部分。我已指定禁用横向模式,但旋转屏幕时方向仍然会发生变化。我错过了什么?我必须在此处添加任何权限吗?
您可以重写每个 activity 的 onConfigurationChanged 方法以自行处理方向更改。否则在您的清单文件中声明 android:configChanges 您根本无法处理它们。
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo."orientation type your preffer");
}
当 android:screenOrientation="portrait" or "landscape"
在 manifest
文件中设置时,如果您想这样做,仍然不会触发任何侦听器,请尝试以编程方式在您的 onConfigurationChanged()
中处理仅纵向模式,在这里您将也可以再次启动 activity。