Android:关于Configurations



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:
<activity android:name=”.TodoList” 
          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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值