当我从 Android 中的设置中将某些权限更改为拒绝时,应用程序重新启动并且语言发生了变化

发布于 2025-01-12 16:49:36 字数 914 浏览 5 评论 0原文

我正在开发一个使用两种语言(英语 - 阿拉伯语)的 Android 应用程序,我的应用程序是一个包含 FragmentsActivity 我正在正确处理整个应用程序中的语言更改,但是当应用程序语言为阿拉伯语时,请更改任何权限以拒绝设置并再次打开应用程序,我的应用程序正在重新启动并且应用程序语言已转换为英语

我已经将语言保存在Sharedpreferences中,语言正确保存为阿拉伯语,并且应用程序在所有情况下都可以正常工作,但是当将权限从设置更改为拒绝时,所有字符串均转换为英语并查看方向 改变。

我尝试在 onRestart() 中更改本地,但它不起作用,所以有什么建议来解决这个问题吗?

如果有帮助,我将根据共享首选项中保存的值更改 Splash screen 中的语言

 public void setLocal(String lang) {


        Resources res = this.getResources();
        Configuration conf = res.getConfiguration();
        conf.locale = new Locale(lang);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            conf.setLayoutDirection(new Locale(lang));
        }
        res.updateConfiguration(conf, res.getDisplayMetrics());
        Consts.first_lang_choose = true;
        

    }

I'm developing an Android app with two languages (English - Arabic) , my app is an Activity that contains Fragments
I'm handling changing of the language across the app correctly but guys when the app language is Arabic then change any permission to deny from setting and open the app again , my app is restarting and the app language converted to be English

I already save the language in the Sharedpreferences , language is saved as Arabic correctly and the app works fine in all cases , but when changing permission from setting to deny , All strings converted to English and views directions change.

I tried to change the local in the onRestart() but it doesn't work , so any suggestion to solve this problem ?

If it would help , I'm changing the language in Splash screen based on the saved value from sharedpreference

 public void setLocal(String lang) {


        Resources res = this.getResources();
        Configuration conf = res.getConfiguration();
        conf.locale = new Locale(lang);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            conf.setLayoutDirection(new Locale(lang));
        }
        res.updateConfiguration(conf, res.getDisplayMetrics());
        Consts.first_lang_choose = true;
        

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软甜啾 2025-01-19 16:49:37

我正在更改启动屏幕中的语言

您需要在所有活动中覆盖区域设置。 Android 框架可以终止您的 Activity(甚至您的应用程序),然后将其恢复到原来的 Activity,而不是通过您的入口点 Activity,例如启动屏幕。

I'm changing the language in Splash screen

You need to have Locale override in all your activities. The Android framework can kill your activities (or even your app) and later restore it to the activity where it was, not going though your entry point activity such as a splash screen.

你穿错了嫁妆 2025-01-19 16:49:37

即使应用程序重新启动,您也需要检查是否正确保存了语言更改。

如果您从 Android 设置中撤销权限,应用程序会重新启动,这是正常现象。

You need to check if you propperly save the language change even when the app restarts.

It is normal that the app restarts if you revoke a permission from the android settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文