Handle runtime activity configuration when font ch

2019-06-26 02:04发布

问题:

Some device configurations can change during runtime, such as screen orientation, keyboard availability, and language. When such a change occurs, Android restarts the running Activity.

We can handle this by using our own configuration. onConfigurationChanged()

But what, if from an Activity, by pressing Home screen, I am jumping to the Settings screen and change the Fonts and come back to my activity? How Can I Handle font changes configuration?

As far I know, these attributes are available:

android:configChanges=["mcc", "mnc", "locale", "touchscreen", "keyboard", "keyboardHidden","navigation", "orientation", "screenLayout","fontScale", "uiMode"]

But there is no attribute available for Font changes.

回答1:

try this code

android:configChanges="orientation|keyboardHidden"

in android manifest file..

<activity android:name=".HomeScreen" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>