Changing Locale within the app itself

前端 未结 6 1826
遇见更好的自我
遇见更好的自我 2020-11-22 01:31

My users can change the Locale within the app (they may want to keep their phone settings in English but read the content of my app in French, Dutch or any other language ..

6条回答
  •  遇见更好的自我
    2020-11-22 01:33

    This is for my comment on Andrey's answer but I cant include code in the comments.

    Is you preference activity being called from you main activity? you could place this in the on resume...

    @Override
    protected void onResume() {
        if (!(PreferenceManager.getDefaultSharedPreferences(
                getApplicationContext()).getString("listLanguage", "en")
                .equals(langPreference))) {
            refresh();
        }
        super.onResume();
    }
    
    private void refresh() {
        finish();
        Intent myIntent = new Intent(Main.this, Main.class);
        startActivity(myIntent);
    }
    

提交回复
热议问题