Change app language programmatically in Android

前端 未结 30 3115
面向向阳花
面向向阳花 2020-11-21 04:34

Is it possible to change the language of an app programmatically while still using Android resources?

If not, is it possible to request a resource in an specific lan

30条回答
  •  青春惊慌失措
    2020-11-21 05:08

    Alex Volovoy answer only works for me if it's in onCreate method of the activity.

    The answer that works in all the methods is in another thread

    Change language programmatically in Android

    Here is the adaptation of the code

    
    
        Resources standardResources = getBaseContext().getResources();
    
        AssetManager assets = standardResources.getAssets();
    
        DisplayMetrics metrics = standardResources.getDisplayMetrics();
    
        Configuration config = new Configuration(standardResources.getConfiguration());
    
        config.locale = new Locale(languageToLoad);
    
        Resources defaultResources = new Resources(assets, metrics, config);
    
    

    Hope that it helps.

提交回复
热议问题