onConfigurationChanged是没有得到所谓的android系统中的任何时间 [英] onConfigurationChanged is not getting called any time in android
问题描述
我已创建示例程序来测试方向。如果人像模式,我倾斜手机反过来我希望我的示例应用来reversePortrait。读很多疑问在这之后 - 提花我们需要需要在使用:
onConfigurationChanged(配置NEWCONFIG)
我尝试了以下工作:
@覆盖
公共无效onConfigurationChanged(配置NEWCONFIG)
{
super.onConfigurationChanged(NEWCONFIG); 。配置C = getResources()getConfiguration(); Log.e(配置,+ C); 如果(c.orientation == Configuration.ORIENTATION_PORTRAIT)
{
//肖像 Log.e(关于修改配置,肖像); }
否则,如果(c.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
//景观
Log.e(在配置变化,横向); }
}
的manifest.xml
的android:configChanges =方向
试过连这个
的android:configChanges =方向|屏幕尺寸
奇怪我不是OnConfigurationChange方法中得到日志。
不知道。这里有什么问题吗?
我使用最低API 8目标阿比18。
有人可以帮我这个?
谢谢!
我不得不改变目标的API后,同样的问题,19(4.4奇巧)
您需要添加的layoutDirection属性比17版本定位更高。
我的属性如下:
<$p$p><$c$c>android:configChanges=\"keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|layoutDirection\"关键是要加'的layoutDirection
I have create sample program to test Orientation. If portrait mode and I tilt the phone the other way round I want my sample app to reversePortrait. After reading lot of questions on this - Figured we need to need use:
onConfigurationChanged(Configuration newConfig)
I was trying out the following:
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
Configuration c = getResources().getConfiguration();
Log.e("Config",""+c);
if (c.orientation == Configuration.ORIENTATION_PORTRAIT)
{
// portrait
Log.e("On Config Change","portrait");
}
else if (c.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
// landscape
Log.e("On Config Change","LANDSCAPE");
}
}
manifest.xml
android:configChanges="orientation"
tried even this
android:configChanges="orientation|screensize"
Strange I am not getting logs inside OnConfigurationChange method.
Not sure. What is the problem here?
I am using minimum api 8 to target Api 18.
Can somebody help me out with this?
Thanks!
I had a same issue after changing target API to 19(4.4 kitkat) You need to add layoutDirection attribute for targeting higher than version 17.
my attribute looks like:
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|layoutDirection"
The key is to add 'layoutDirection'
这篇关于onConfigurationChanged是没有得到所谓的android系统中的任何时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!