首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >onConfigurationChanged不为API17工作

onConfigurationChanged不为API17工作
EN

Stack Overflow用户
提问于 2020-03-22 11:52:32
回答 1查看 119关注 0票数 0

我想触发一些东西,如果桌子是从纵向倾斜到景观,反之亦然。

然而,onConfigurationChanged永远不会被触发。我读过几年前堆满风扇提出的几个问题,但没有一个是有效的。

例如,在Android中添加android:configChanges="orientation|screenSize"。下面是AndroidManifest.xml、应用程序和调试日志,

谢谢

代码语言:javascript
运行
复制
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
代码语言:javascript
运行
复制
<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>
代码语言:javascript
运行
复制
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'
}
EN

Stack Overflow用户

回答已采纳

发布于 2020-03-22 15:52:31

您应该在"activity“标记之间放置以下字符串,而不是在"application”之间放置以下字符串,尝试如下所示:

代码语言:javascript
运行
复制
<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>
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60798971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档