getActivity / MultiLanguages

Android 多语种适配框架,兼容高版本,适配第三方库语种
Apache License 2.0
982 stars 123 forks source link

切换语言之后,getApplicationContext()关联的还是旧的语言配置 #7

Closed lan2000 closed 3 years ago

lan2000 commented 3 years ago

切换语言之后,调用getApplication().getApplicationContext().getResources().getConfiguration().getLocales()返回还是旧的 调用getApplicationContext().getString(resid)获取的还是旧语言的字符串

getActivity commented 3 years ago

经过核实,确实存在这个问题,已经修复此问题。

getActivity commented 3 years ago

languages.zip

lan2000 commented 3 years ago

能简单说说是啥原因吗,我今天测试了很久。

------------------ 原始邮件 ------------------ 发件人: "Android轮子哥"<notifications@github.com>; 发送时间: 2021年1月19日(星期二) 晚上9:00 收件人: "getActivity/MultiLanguages"<MultiLanguages@noreply.github.com>; 抄送: "若即若离若迷离"<122775467@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [getActivity/MultiLanguages] 切换语言之后,getApplicationContext()关联的还是旧的语言配置 (#7)

languages.zip

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

lan2000 commented 3 years ago

我调试的时候也发现了,添加resources.updateConfiguration(config, resources.getDisplayMetrics());   全局application的语言就正常了,不过看文档,这句代码不是过时了吗,用context.createConfigurationContext(config)替换。 我测试也是在安卓10测试。 新API反而有问题,贼郁闷。

------------------ 原始邮件 ------------------ 发件人: "Android轮子哥"<notifications@github.com>; 发送时间: 2021年1月19日(星期二) 晚上9:00 收件人: "getActivity/MultiLanguages"<MultiLanguages@noreply.github.com>; 抄送: "若即若离若迷离"<122775467@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [getActivity/MultiLanguages] 切换语言之后,getApplicationContext()关联的还是旧的语言配置 (#7)

languages.zip

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

lan2000 commented 3 years ago

初始设置俄语,主页有webview控件的话,启动的BaseApplication里面onCreate里面设置语言(比如俄语)MultiLanguages.setAppLanguage(this,new Locale("ru"));。  进入页面之后,使用getApplicationContext().getResources().getString() 获取的字符串不是刚才设置的俄语。 如果再次设置MultiLanguages.setAppLanguage,则getApplicationContext().getResources().getString()才获取俄语。

------------------ 原始邮件 ------------------ 发件人: "Android轮子哥"<notifications@github.com>; 发送时间: 2021年1月19日(星期二) 晚上9:00 收件人: "getActivity/MultiLanguages"<MultiLanguages@noreply.github.com>; 抄送: "若即若离若迷离"<122775467@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [getActivity/MultiLanguages] 切换语言之后,getApplicationContext()关联的还是旧的语言配置 (#7)

languages.zip

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

getActivity commented 3 years ago

小伙子,关于 WebView 导致 Activity 语种失效这个问题,我已经补充了解决方案的文档在项目主页上,不过你得先更新一下框架版本,感谢小伙子的支持。

lan2000 commented 3 years ago

😀👍 还有就是既然webview也关注了,干脆再提示旋转屏幕横竖屏导致多语言失效解决

getActivity commented 3 years ago

小伙子,手机屏幕旋转我这边已经测试过了,是没有问题的,不信你下载 Demo 试试看