在配置文件里,如果设置android:targetSdkVersion=”18”,那么必须android:configChanges=”orientation|keyboardHidden|screenSize”,activity中才会调用 onConfigurationChanged 监听;如果去掉android:targetSdkVersion=”18”
android:configChanges=”orientation”也会监听onConfigurationChanged变化
activity中代码如下
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
Log.d("test","----------横屏------------");
}else if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
Log.d("test","----------竖屏------------");
}
}