我的应用程序支持3种(很快4种)语言.由于几个语言环境非常相似,我想让用户选择在我的应用程序中更改语言环境,例如意大利人可能更喜欢西班牙语而不是英语.
有没有办法让用户在可用于应用程序的语言环境中进行选择,然后更改使用的语言环境?我不认为为每个Activity设置语言环境是一个问题,因为它是在基类中执行的简单任务.
我只需按一下按钮即可更改应用程序区域设置。它可以在 AVD 上完美运行,也可以在具有 API 30 的实际设备上调试和发布构建 APK。
但是,一旦发布,它就无法与应用程序的 Play 商店版本一起使用。区域设置永远不会改变。
请帮忙!谢谢你!
这是SettingsFragment中的代码:
private void setAppLocale(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration config = context.getResources().getConfiguration();
config.setLocale(locale);
context.createConfigurationContext(config);
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
Intent refresh = new Intent(getActivity().getApplicationContext(), MainActivity.class);
startActivity(refresh);
getActivity().finish();
}
Run Code Online (Sandbox Code Playgroud)
一旦按下按钮,上面的代码就会被调用,并且选择也会被放入共享首选项中。活动被刷新并加载主要活动,但区域设置从未更改。
这就是我的 MainActivity 的样子:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideSystemUI();
sharedPref = getPreferences(Context.MODE_PRIVATE);
selectedLanguage = sharedPref.getString("Test.SL.LanguageName", language);
selectedTheme = sharedPref.getString("Test.SL.ThemeName", "Light");
if (selectedTheme.equals("Light")){
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else if (selectedTheme.equals("Dark")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
if (selectedLanguage.equals("Sinhala")) {
language = …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个功能,用户可以在运行时从应用程序内部选择各种语言,它运行良好,直到我以 APK 格式在 Play 商店上部署应用程序,但自从我开始以App Bundle 格式部署我的应用程序后它停止工作。默认字符串资源不会被用户选择的资源替换,但是当我从设备的设置选项更改整个设备语言时,我的应用程序将使用来自 Play 商店的新配置资源进行更新,并且一切正常。有什么方法可以强制所有字符串资源与基本 apk 或我不知道的任何其他方式一起推送?请帮忙。我用来更改语言的代码是 -
Locale locale = new Locale(langCode); //langCode is the code of the language user has selected
Locale.setDefault(locale);
Resources res = parentContext.getResources();
Configuration config = res.getConfiguration();
config.setLocale(locale); // = locale;
res.updateConfiguration(config, parentContext.getResources().getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud) 我的应用程序支持多种语言,并且可以在应用程序内动态更改,并且以前与 APK 运行良好。但是当我采用 AAB 而不是 APK 时,我遇到了这个问题。现在我的应用程序不会更改应用程序内的语言,但如果我要更改设备的语言,那么它也会更改我的应用程序的语言。对于上述问题是否有任何解决方案而不是使用
bundle {
language {
enableSplit = false
}
}
Run Code Online (Sandbox Code Playgroud) 我完全陷入困境。请帮助我。\n 我开发了一个以英语和阿拉伯语两种语言运行的医院应用程序。\n 我允许用户在两个部分选择语言。\n 1.登录阶段后。\n 2.在设置页面上。\n 每当用户选择语言时,应用程序都会以该语言运行(英语或阿拉伯语)。\n 当我在本地运行该应用程序时,该应用程序正在更改语言。我在 Google Play 商店上发布了该应用程序进行测试。之后我下载了它。当我选择阿拉伯语言应用程序时,它不会读取本地存储在values-ar文件夹中的阿拉伯语值。\n我在互联网上搜索了两天。我没有找到任何答案......
\n\nI am giving you my codes....\n\n1.User Selecting language after login stage.\n\nimport android.content.Intent;\nimport android.content.res.Configuration;\nimport android.content.res.Resources;\nimport android.support.annotation.Nullable;\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.util.DisplayMetrics;\nimport android.view.View;\nimport android.widget.Button;\n\nimport com.icelab.home.hospital.Activities.Confirm.ConfirmpageActivity;\nimport com.icelab.home.hospital.Activities.Patientpage.PatientpageActivity;\nimport com.icelab.home.hospital.R;\nimport com.icelab.home.hospital.Utils.PrefManager;\n\nimport java.util.Locale;\n\npublic class SelectLanguages extends AppCompatActivity {\nButton btn_English,btn_arab;\nPrefManager prefManager;\nprivate static final int REQUEST_CHANGE_LANGUAGE = 1;\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_select_languages);\n prefManager=new PrefManager();\n btn_English=findViewById(R.id.btn_English);\n btn_arab=findViewById(R.id.btn_arab);\n\n\n btn_English.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View view) {\n prefManager.saveLanguageSelected(0);\n prefManager.languageSelection(1);\n setLocale("en");\n // loadPage();\n }\n });\n\n btn_arab.setOnClickListener(new View.OnClickListener() {\n …Run Code Online (Sandbox Code Playgroud)