我有兴趣知道当 Android 设备旋转时(即配置更改时)哪些方法被覆盖?
onSaveInstanceState(...)
, onConfigurationChanged(...)
, onRestoreInstanceState(...)
- 类似的东西?
对我来说,聆听与更改配置相关的整个过程也很有趣。谢谢。
根据 android 开发人员参考,您必须使用:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
欲了解更多信息,请参阅:http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange
您可能有兴趣查看:http://developer.android.com/guide/topics/manifest/activity-element.html#config http://developer.android.com/guide/topics/manifest/activity-element.html#config
在这里你可以找到所有你可以监听的配置监听器。
请记住将它们放入 android 清单中:
<activity
android:configChanges=["orientation"]
. . .
</activity>
希望这可以帮助...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)