Skip to content

Commit

Permalink
Fix appearance changed into wrong activity (#34)
Browse files Browse the repository at this point in the history
the original `AppCompatDelegate.setDefaultNightMode()` is a global setup. when changing the night mode, it will actually call HomeActivity's `onConfigurationChanged`. this pr tries to set night mode to current activity by using the `setLocalNightMode()`
  • Loading branch information
Kudo authored and alanjhughes committed Mar 20, 2024
1 parent 41eb880 commit d8402f3
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,20 @@ private String colorSchemeForCurrentConfiguration(Context context) {

@Override
public void setColorScheme(String style) {
int nightMode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
if (style.equals("dark")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
nightMode = AppCompatDelegate.MODE_NIGHT_YES;
} else if (style.equals("light")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
nightMode = AppCompatDelegate.MODE_NIGHT_NO;
} else if (style.equals("unspecified")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
nightMode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
}

Activity activity = getCurrentActivity();
if (activity instanceof AppCompatActivity) {
((AppCompatActivity) activity).getDelegate().setLocalNightMode(nightMode);
} else {
AppCompatDelegate.setDefaultNightMode(nightMode);
}
}

Expand Down

0 comments on commit d8402f3

Please sign in to comment.