方向改變時,onConfigurationChanged()方法沒有被調(diào)用。
在AndroidManifest中,添加以下代碼
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我在android:configChanges="orientation|screenSize"忘記加screenSize,當方向改變時沒有觸發(fā)onConfigurationChanged()的回調(diào)。