📌  相关文章
📜  以编程方式实现 Android 深色主题 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:06.909000             🧑  作者: Mango

代码示例1
You can enable/disable application's dark theme just by:

enable dark theme:
     AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
    
forcefully disable dark theme:
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

set app theme based on mobile settings of dark mode, i.e. if dark mode is
enabled then the theme will be set to a dark theme, if not then the 
default theme, but this will only work in version >= Android version Q (10) :
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_
    SYSTEM)