2

In my app, i am asking for language, can be either English or German. The selected language and its iso code is saved into preferences. On the basis of selected language i need to change all the texts into corresponding language.

For this, i have created res/values and res/values-de; each folder containing a strings.xml file. Issues are: 1) I am opening camera as well as a screen using opengl. After navigating via both of them, the texts does not change completely into german(if was chosen). Some text values change into German, rest not even on the same page. 2) Even without going through camera and opengl screens, the results are not achieved 100% always but gives a better result always as compared to case 1.

My implementations: 1) in onResume() of splash screen, i am changing locale based on preferences with the help of config.locale(). 2) in manifest file, each activity is set with activity:configChanges="locale". 3) in camera activity and opengl activity, onConfigurationChanged() is overridden in which i am again setting locale as per preferences.

please guide how to solve the locale issue.

4

3 回答 3

0
  • 检查点 1: 资源的部分更新。确保您拥有以所有语言正确命名的资源。
  • 此外,您可以尝试使用此代码。这就是我更新应用程序语言环境的方式:

     public void updateLocale(String language) {
        Locale myLocale = new Locale(language);
        Locale.setDefault(myLocale);
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = myLocale;
        res.updateConfiguration(conf, dm);
    }
    

让我知道它是否有帮助!

于 2013-04-23T06:41:59.810 回答
0

我相信您需要在您的 AndroidManifest 文件中添加一些内容来指示区域设置更改。这是一个例子:http ://android.programmerguru.com/android-localization-at-runtime/

于 2013-04-23T06:42:51.853 回答
0

我的应用程序也有类似的问题。应用程序具有土耳其语和英语之间的强制语言更改选项。如果我的设备语言是英语并且我使用土耳其语的应用程序,我可以使用以下代码轻松转换语言:

public void setAppLanguage(String languageCode) {

        String countryCode;

        if (languageCode.equals("tr")){
            countryCode = "TR";
        }else{
            countryCode = "US";
        }

        Locale locale = new Locale(languageCode, countryCode);
        Locale.setDefault(locale);
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = locale;
        res.updateConfiguration(conf, dm);

        loginPrefsEditor.putString("uLang",languageCode);
        loginPrefsEditor.apply();


    }

但是,当我打开相机并从中返回时,应用程序语言会变回默认手机语言。当我打开相机时,应用程序会终止我的活动。从相机返回后,它会刷新所有内容。所以为了解决这个问题,我把我的强制更改语言方法放在每个活动的onResume()方法中。

通过这样做,我将能够解决这个问题。

于 2015-07-09T14:44:18.040 回答