更改区域设置后不会调用onConfigurationChange

编程入门 行业动态 更新时间:2024-10-11 21:24:54
本文介绍了更改区域设置后不会调用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

本文发布于:2023-11-13 11:05:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584191.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区域   onConfigurationChange

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!