onConfigurationChanged

onConfigurationChanged

如果桌子从纵向倾斜到横向,反之亦然,我想触发一些操作。
但是onConfigurationChanged永远不会被触发。
我读了几年前从堆栈溢出风扇提出的几个问题,但没有一个起作用。
例如,在Android中添加android:configChanges="orientation|screenSize"
以下是AndroidManifest.xml,应用程序和调试日志,
谢谢

D/ViewRootImpl@d3690a3[MainActivity]: Relayout returned: old=[0,0][1920,1200] new=[0,0][1920,1200]
    result=0x7 surface={true 3874265088} changed=true
D/OpenGLRenderer: eglCreateWindowSurface = 0xe8985120, 0xe6ec9808
D/ScrollView:  onsize change changed
E/ViewRootImpl: sendUserActionEvent() returned.
I/Choreographer: Skipped 51 frames!  The application may be doing too much work on its main thread.
D/ViewRootImpl@d3690a3[MainActivity]: MSG_RESIZED_REPORT: frame=[0,0][1920,1200] ci=[0,36][0,72] vi=
    [0,36][0,72] or=2
D/ViewRootImpl@d3690a3[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager: prepareNavigationBarInfo() DecorView@15f6fa0[MainActivity]
D/InputMethodManager: getNavigationBarColor() -855310
D/InputMethodManager: prepareNavigationBarInfo() DecorView@15f6fa0[MainActivity]
getNavigationBarColor() -855310
V/InputMethodManager: Starting input: tba=com.example.android.predictiongua ic=null mNaviBarColor
    -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager: startInputInner - Id : 0
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport: Input channel constructed: fd=76
Input channel destroyed: fd=77
V/item: 7
V/item: 3
V/item: 8


<application
    android:allowBackup="true"
    android:icon="@mipmap/android_icon"
    android:label="xxxxxx"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:configChanges="screenSize|keyboardHidden|orientation"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>


android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.example.android.xxxxxx"
    minSdkVersion 17
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'

implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
implementation 'com.github.aakira:expandable-layout:1.6.0@aar'
}

最佳答案

您应该将以下字符串放置在“活动”标记之间,而不是放置在“应用程序”之间,并尝试使用它,如下所示:

<application
    android:allowBackup="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:configChanges="screenSize|keyboardHidden|orientation" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

关于java - onConfigurationChanged不适用于API17,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60798971/

10-12 04:20