I am working on LGE Nexus 5x which runs on Android 7.0 & I want to restrict any system font changes to change my application font size.
I have already gone through this question, and also I have tried this answer which works perfectly upto Marshmallow. But doesn't work on Nougat.
In my Application class I have added these lines;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
adjustFontScale(new Configuration(newConfig));
}
public void adjustFontScale(Configuration configuration) {
if (configuration != null && configuration.fontScale != 1.0) {
configuration.fontScale = (float) 1.0;
DisplayMetrics metrics = getResources().getDisplayMetrics();
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(metrics);
metrics.scaledDensity = configuration.fontScale * metrics.density;
getBaseContext().getResources().updateConfiguration(configuration, metrics);
}
}
In manifest, under application tag
I have declared;
android:configChanges="fontScale"
But that doesn't work on Nougat devices even though onConfigurationChanged
is called and executed without any exception.
Any help will be appreciated.