To manually handle config changes, simply add the "android:configChanges" attribute to the activity in your Manifest file. For example:
<activity
android:configChanges="fontScale"
android:name="net.company.app.MainActivity"
android:label="@string/app_name" >
There's a listing of the configChanges defined here: http://developer.android.com/guide/topics/manifest/activity-element.html.
The next step, is to override the onConfigurationChanged() method in the activity, like this:
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.i(TAG, "newConfig.fontScale = " + newConfig.fontScale);
super.onConfigurationChanged(newConfig);
}
When the font size changes in the device settings, your onConfigurationChanged() method is called and an object containing the new device configuration is passed to the method, for you to handle as you please.

No comments:
Post a Comment