I faced this bug recently and found a solution. See my question here
Edge-to-edge doesn't work when activity recreated or AppCompatDelegate.setDefaultNightMode() applied