gpt4 book ai didi

android - onConfigurationChanged 未被调用

转载 作者:行者123 更新时间:2023-11-29 22:18:55 33 4
gpt4 key购买 nike

为什么当我在模拟器中切换方向 (ctrl+F11) 时,没有调用 onConfigurationChanged 覆盖方法。

public class HelloSample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
System.out.println("Change in Orientation");
}

}

在 manifest.xml 中

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloSample"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

最佳答案

使用真机,模拟器不支持。

关于android - onConfigurationChanged 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7815578/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com