我正在开发一个android项目,并且用两种语言本地化了我的应用程序,问题是,当我直接从android studio运行我的应用程序但在Google Play商店中上传项目并从Play商店下载该应用程序时,它运行良好它的本地化在某些版本的Android中不起作用。
这是设置本地语言的Java代码。
private static Context updateResources(Context context) {
Locale locale = new Locale("fa","AF");
Locale.setDefault(locale);
Resources res = context.getResources();
Configuration config = new Configuration(res.getConfiguration());
if (Build.VERSION.SDK_INT >= 17) {
config.setLocale(locale);
context = context.createConfigurationContext(config);
} else {
config.locale = locale;
res.updateConfiguration(config, res.getDisplayMetrics());
}
return context;
}
Run Code Online (Sandbox Code Playgroud)
这是我的英文版面文件。
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="update">Update</string>
<string name="app_version_title">New version</string>
<string name="app_version_title_second">is now available</string>
<string name="logout_msg">Are you sure you want to logout?</string>
<string name="logout_title">Log Out?</string>
<string name="languages">Languages</string>
<string name="km">Km</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
这是我的Persion布局文件。
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string …Run Code Online (Sandbox Code Playgroud)