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 Jan 23, 2024
1 parent 5aa6b72 commit cf55a59
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 cf55a59

Please sign in to comment.