I have a little problem I need to resolve. 
In my application I will have a settings where I will change the language of my app from english to swedish and back. So I wonder how I should do this? 
Can I change to a different strings.xml file or do I have to change all the text in my strings.xml manually when the user wants to change lanuage?
Please come with tips and examples how I should solve this!
            Asked
            
        
        
            Active
            
        
            Viewed 2,862 times
        
    1
            
            
         
    
    
        JussT
        
- 181
- 1
- 4
- 15
- 
                    possible duplicate of [Change language programatically in Android](http://stackoverflow.com/questions/2900023/change-language-programatically-in-android) – Sam Oct 30 '12 at 16:07
2 Answers
5
            You can do that with this:
String languageToLoad  = "your language code";
Locale locale = new Locale(languageToLoad); 
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, 
getBaseContext().getResources().getDisplayMetrics());
With this you are basically just changing your locale, therefor also your language
 
    
    
        Ahmad
        
- 69,608
- 17
- 111
- 137
- 
                    So I make my own folder values-swe and then I put my strings.xml in swedish? But do I need all the other .xml files too? Like array, color, styles etc. ? – JussT Oct 30 '12 at 16:07
- 
                    1you have to create a values-swe folder and then you can put your strings.xml file in there. Just everything you want to be available in different languages – Ahmad Oct 30 '12 at 16:08
- 
                    
- 
                    1The default folder is usually the folder with the english strings, so just redo this and set the locale to "en" – Ahmad Oct 30 '12 at 16:21
1
            
            
        You will need to change the locale, locally:
Resources res = context.getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = new Locale('fr');
res.updateConfiguration(conf, dm);
 
    
    
        Community
        
- 1
- 1
 
    
    
        shkschneider
        
- 17,833
- 13
- 59
- 112