0

I know switching dark mode on android programmatically is easy with below code.

    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

I want to know how to do it like whatsapp/slack which won't restart the app. User will still be in preferences fragment and mode changes there right away. If I try above line, my activity is recreated and first fragment is launched but not preference fragment.

How to handle it the way they are handling it?

4

1 回答 1

0

放入android:configChanges="...|uiMode|..."该活动的清单并使用日/夜主题,这样做,切换是自动的,并且只有 0 行代码

于 2020-12-11T17:20:29.393 回答