更改区域设置后不会调用onConfigurationChange [英] onConfigurationChange not called after changing locale

查看:169
本文介绍了更改区域设置后不会调用onConfigurationChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从一个片段更新语言的片段内容。所以我想到使用onConfigurationChange方法,这是在我的主要活动(这个活动控制所有的片段),并重新创建所有片段的变化的语言环境。但是这种方法不是在更改语言环境时调用。

I have to refresh the fragments contents on change of language from one fragment. So I thought of using onConfigurationChange method which is in my Main activity (this activity controls all the fragments) and recreate all the fragments on change of locale. But this method is not being called on change of locale.

我在清单文件的活动标签下包含了locale。 onConfigurationChange在方向改变时被调用。

I have included locale under the activity tag of manifest file. onConfigurationChange is being called on change of orientation.

我正在更改此链接中提供的语言在Android中以程式码方式更改语言及其工作方式。

i am changing language as given in this link Change language programatically in Android and its working.

有人可以澄清修正此问题需要做哪些变更。

Can someone please clarify what change would be required to fix this issue.

推荐答案

对于遇到这个问题的其他人来说,OP是正确的但有点不清楚。

你必须定义 android:configChanges =layoutDirection | locale以调用 onConfigurationChanged()
我假设这是必要的,因为区域设置更改也可能影响布局方向(对于RTL语言),所以声明只是语言环境可能不够,但这只是我对这个问题的假设。

For others who encounter this issue the OP was right but a bit unclear.
You have to define android:configChanges="layoutDirection|locale" in order for onConfigurationChanged() to be called.
I assume that this is necessary because locale change might also affect layout direction (for RTL languages) so declaring just locale might not be enough, yet this is only my assumption on this matter.

这篇关于更改区域设置后不会调用onConfigurationChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆