gpt4 book ai didi

android - 在我的应用程序中更改设备语言

转载 作者:行者123 更新时间:2023-11-29 01:54:32 24 4
gpt4 key购买 nike

我希望能够通过在我的应用程序中单击按钮来更改我的手机设置。准确地说,我想更改手机的语言。到目前为止,我创建了 values/strings 和 values-iw/strings(希伯来语字符串),并在单击按钮后更改了配置,如下所示:

    if (myLocale != null) {
Locale.setDefault(myLocale);
Configuration config = new Configuration();
config.locale = myLocale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
}

此代码更改了语言环境(我不确定语言环境和语言之间的区别)但它不会影响我的所有 Activity 。因此,我试图直接从我的应用程序更改手机的语言设置,但没有成功。有谁知道如何让这段代码影响我的所有 Activity ?或者相反 - 如何更改我的手机语言(反射(reflection)??)...


为了让自己清楚 - 我有 Activity A 调用 Activity B(我有更多的 Activity
android:launchMode="singleInstance"在 AndroidManifest 中)。在 Activity B 中,我更改了区域设置语言并通过以下行返回到 Activity A:

    final Intent intent2 = new Intent(this, MainActivity.class);
startActivity(intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
finish();

语言环境更改不会影响 Activity A(但会影响所有其他 Activity,其中包括 Activity B)。我假设它不影响 Activity A 的原因是 Activity A 仍在堆栈中。更改语言环境时我没有设法影响 Activity A。有谁知道如何影响 Activity A?

最佳答案

I want to be able to change my phone settings within a button click inside my app. To be precise, I would like to change the phone's language.

对不起,那是不可能的。

within a button click I changed the configuration as follows

至多,这会影响您的应用,而不是“手机”。

Does anyone have an idea how do I make this code affect all my activities?

在每个 Activity 中运行相同的代码,例如 onResume()

关于android - 在我的应用程序中更改设备语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15975413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com