美文网首页
Android onConfigurationChanged()

Android onConfigurationChanged()

作者: 启才 | 来源:发表于2017-07-11 22:34 被阅读54次

方向改变时,onConfigurationChanged()方法没有被调用。
在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,当方向改变时没有触发onConfigurationChanged()的回调。

相关文章

网友评论

      本文标题:Android onConfigurationChanged()

      本文链接:https://www.haomeiwen.com/subject/ohhvhxtx.html