Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*That's how we do it. In Application class override onConfigurationChanged() like this. If you want different behavior for different activities - override onConfigurationChanged() in Activity.
- Don't forget to add manifest tag android:configChanges="fontScale" since you are hadnling this configuration change yourself.*/
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- // In some cases modifying newConfig leads to unexpected behavior,
- // so it's better to edit new instance.
- Configuration configuration = new Configuration(newConfig);
- SystemUtils.adjustFontScale(getApplicationContext(), configuration);
- }
- //In some helper class we have adjustFontScale() method.
- public static void adjustFontScale(Context context, Configuration configuration) {
- if (configuration.fontScale != 1) {
- configuration.fontScale = 1;
- DisplayMetrics metrics = context.getResources().getDisplayMetrics();
- WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
- wm.getDefaultDisplay().getMetrics(metrics);
- metrics.scaledDensity = configuration.fontScale * metrics.density;
- context.getResources().updateConfiguration(configuration, metrics);
- }
- }
- //WARNING! That will totally ignore Accessibility Font Scale user settings and will prevent your App fonts scaling!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement