开发者

changing the language of app without changing the settings of device

I am m开发者_StackOverflowaking an android app in which i want to change the language of app on selecting a particular language in spinner without changing the language of device.I have made different string files for all language. Now what to do next?? Can anyone please help me over this? thanks


Most simple way is just to change VM's locale, like:

Locale locale=new Locale("zh");  //Chinese    
Locale.setDefault(locale);  //set VM's default locale


Once I wanted to implement a multiple language feature for my application. Where that language was not even supported by android.

I made the appropriate strings for all the application and stored them in my resources. Then I kept the language selection in my shared preferences, so that when user opens the app the next time, we can show the previously selected language. I implemented the code and language changing in my OnResume() function of Activity. the code was like:

        if(SelectedLanguage.compareTo("ar")==0)
        {
            String text = getString(R.string.ar_Options);
            tv_Options.setText(ArabicUtilities.reshape(text));

            text = getString(R.string.ar_Minimize);
            tv_Minimize.setText(ArabicUtilities.reshape(text));
        }
        else
        {
            String text = getString(R.string.en_Options);
            tv_Options.setText(text);

            text = getString(R.string.en_Minimize);
            tv_Minimize.setText(text);
        }           

I hope you get the basic idea. In this way you don't have to change the lanuguage of your device and you can provide multiple languages for your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜