推出具有不同的资源文件的Andr​​oid应用程序 [英] Launch an android application with different resource file

查看:106
本文介绍了推出具有不同的资源文件的Andr​​oid应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在2个版本推出的应用程序。

I have an application which can be launched in 2 versions.

2应用之间的主要区别是资源文件。 (有些地方被重命名,但应用程序只处理一种语言)

The main difference between the 2 application are the resource file. (Some parts are renamed, but the application handle only one language)

是否有可能与@字符串/个招呼,或者R.string.hello与Android的某些特定设置的2 strings.xml档案转?如果没有,什么是这个问题最好的办法?我想象,我可以使用一些Eclipse功能来切换xml文件,如果有一些参数...我preFER只有APK包,但它不是强制性的。

Is it possible to switch between 2 strings.xml file with @string/hello or R.string.hello with some specific settings in android ? If not, what is the best approach to that problem ? I imagined that I can use some eclipse feature to switch the xml file if there is some parameter ... I prefer have only apk package but it isn't mandatory.

我不能改变语言的客户端...

I can't change the language on the client ...

问候

修改

好主意阿莱克斯。我重构了谟到库,并具有良好的语言环境参数启动它。在这种情况下,我可以有良好的数据库3型动物的项目。

good idea Aleks. I refactored the projet into a library and launched it with good locale parameters. In that case I can have 3 differents project with the good database.

推荐答案

如果我理解正确的话,你希望能够切换应用程序的语言不改变手机上的语言。我想,我可以看到一个场景,这可能是有用的。

If I understand correctly, you want to be able to switch the language of the application without changing the language on the phone. I suppose, I can see a scenario where this can be useful.

您可以尝试做这样的事情。

You could try to do something like this.

1)建立多字符串资源您的应用程序,就像你,如果你要支持多语言环境/语言。

1) Build your app with multiple string resources just like you would if you were to support multiple locales/languages.

2)在您的清单中添加 configChanges =区域设置来您的活动:

2) In your manifest, add configChanges="locale" to your activity:

<activity android:name=".Main" android:configChanges="locale" android:label="@string/app_name" />

3)的第一次的应用程序启动时,将在客户端手机的语言。当用户在您的应用改变了语言,保存的任何方式,你preFER(sqlite的,文件,应用程序包等),并强制重新启动应用程序的新的语言。

3) The first time the app starts, it will be in the language of the client phone. When the user changes the language in your app, save the new language in whatever way you prefer (sqlite, file, app bundle, etc.) and force-restart the app.

4)当你的应用程序启动时,检索保存的语言并设置为默认语言环境吧:

4) When your app is starting, retrieve the saved language and set default Locale to it:

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        //load saved language
        String languageToUse  = ...
        if(languageToUse != null)
        {
            Locale locale = new Locale(languageToLoad); 
            Locale.setDefault(locale);
            Configuration config = new Configuration();
            config.locale = locale;
            getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
        }
        this.setContentView(R.layout.main);
    }

我还没有尝试过这个自己,所以这只是一个一般的想法 - 看看它是否适合你。

I haven't tried this myself, so this is just a general idea - see if it works for you.

这篇关于推出具有不同的资源文件的Andr​​oid应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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