我在我的应用程序"英语"和"法语"中实现了两种语言,并且它们都可以单独运行.当我试图用设备语言检查语言变化时,问题就出现了.
最近我的应用程序和设备语言是"法语".现在我正在将设备语言从"法语"更改为"英语",然后从后台打开应用程序,应用程序语言仍处于"法语"中,但是在应用程序中,导航抽屉相关内容更改为"英语"
下面是我在GlobalClass中更改语言的代码
public void changelanguage(String languageToLoad, Context context) {
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
Run Code Online (Sandbox Code Playgroud)
以下是在MainActivity和Splashscreen上比较语言的代码
gc = GlobalClass.getInstance()
prefsWrapper = PreferencesWrapper(applicationContext)
sel_langague = prefsWrapper.getPreferenceStringValue(SipConfigManager.LANGUAGE)
println("Language Main : " + sel_langague)
var languageToLoad = ""
if (sel_langague == "0") {
languageToLoad ="en"
} else {
languageToLoad ="fr"
}
gc!!.changelanguage(languageToLoad, baseContext)
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何解决这个问题?