设置语言环境的应用程序插件 [英] Setting locale to app widget

查看:141
本文介绍了设置语言环境的应用程序插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序强制执行独立的设备设置一定的语言环境吧。这是一个临时决定,直到字符串翻译正确。

Our application enforces a certain locale to it independent of device settings. This is a temporary decision until the strings are translated properly.

    Configuration config = sContext.getResources().getConfiguration();
    if (!sDefaultLocale.equals(config.locale)) {
            Locale.setDefault(sDefaultLocale);
            config.locale = sDefaultLocale;
            sContext.getResources().updateConfiguration(config,
                    sContext.getResources().getDisplayMetrics());

    }

不幸的是,迫使区域设置不应用插件工作时,部件仍然使用设备的区域设置。我正在寻找一种方法,使应用程序部件承担同样的语言环境。

Unfortunately, forcing locale doesn't work with app widget, the widget still uses locale of device. I am looking for a way to make the app widget assume the same locale.

推荐答案

改变你需要更新应用小部件的语言环境后。而重要的是,在创建新的RemoteViews时,您需要设置您的所有字符串的编程,使用remoteViews.setTextViewText(..)。

After changing the locale you need to update the app widgets. And the important part is that when creating new RemoteViews, you need to set all your strings programmatically, using remoteViews.setTextViewText(..).

如果应用程序窗口小部件字符串资源在XML定义。(机器人:文字=@字符串/ ...) - 他们不会设置新区域后改变

if app widget string resources are defined in XML (android:text="@string/...") - they will not be changed after setting the new locale.

这篇关于设置语言环境的应用程序插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆