Android:关于Configurations
16lz
2021-01-23
The following list describes the confi guration changes you can specify:
❑ orientation The screen has been rotated between portrait and landscape.
❑ keyboardHidden The keyboard has been exposed or hidden.
❑ fontScale The user has changed the preferred font size.
❑ locale The user has chosen a different language setting.
❑ keyboard The type of keyboard has changed; for example, the phone may have a 12 keypad
that fl ips out to reveal a full keyboard.
❑ touchscreen or navigation The type of keyboard or navigation method has changed. Neither of these events should normally happen.
You can select multiple events to handle by separating the values with a pipe (|).
The following XML snippet shows an activity node declaring that it will handle changes in screen orientation and keyboard visibility:
android:label=”@string/app_name”
android:theme=”@style/TodoTheme”
android:configChanges=”orientation|keyboard”/>
Adding this attribute suppresses the restart for the specifi ed confi guration changes, instead, triggering
the onConfigurationChanged method in the Activity. Override this method to handle the confi guration changes using the passed-in Configuration object to determine the new confi guration values, as
shown in the following skeleton code. Be sure to call back to the super class and reload any resource
values that the Activity uses in case they’ve changed.
@Override
public void onConfigurationChanged(Configuration _newConfig) {
super.onConfigurationChanged(_newConfig);
[ ... Update any UI based on resource values ... ]
if (_newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
[ ... React to different orientation ... ]
}
if (_newConfig.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO) {
[ ... React to changed keyboard visibility ... ]
}
}
When onConfigurationChanged is called, the Activity’s Resource variables will have already been
updated with the new values so they’ll be safe to use.
Any confi guration change that you don’t explicitly fl ag as being handled by your application will still
cause an application restart without a call to onConfigurationChanged
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer