Skip to content

Instantly share code, notes, and snippets.

@logcat
Created July 15, 2015 06:50
Show Gist options
  • Save logcat/d922f64b8f61990a25db to your computer and use it in GitHub Desktop.
Save logcat/d922f64b8f61990a25db to your computer and use it in GitHub Desktop.
Android activity role to change and test different locales
public static final Locale FRENCH_LOCALE = new Locale("fr", "FR");
@Rule
public ActivityTestRule<SplashScreenActivity> activityRule = new ActivityTestRule(SplashScreenActivity.class, true, true) {
@Override
protected void beforeActivityLaunched() {
super.beforeActivityLaunched();
Locale.setDefault(FRENCH_LOCALE);
Resources res = getInstrumentation().getTargetContext().getResources();
Configuration configuration = new Configuration();
configuration.locale = FRENCH_LOCALE;
res.updateConfiguration(configuration, res.getDisplayMetrics());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment