# 夜间模式NightModeDemo **Repository Path**: hspbc/night-mode-demo ## Basic Information - **Project Name**: 夜间模式NightModeDemo - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-17 - **Last Updated**: 2022-04-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 效果图 ![](https://upload-images.jianshu.io/upload_images/6169789-312ff00313dcc754.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/600) # 实现方案 1. Manifest中指定application主题 ``` android:theme="@style/Theme.NightModeDemo" ``` 2. res下新建values-night目录,新建themes.xml ![](https://upload-images.jianshu.io/upload_images/6169789-ba68156ecd6e4169.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/600) 3. 切换夜间模式 ``` private fun changeNightMode(isNightMode: Boolean) { (getSystemService(UI_MODE_SERVICE) as UiModeManager).nightMode = if (isNightMode) UiModeManager.MODE_NIGHT_YES else UiModeManager.MODE_NIGHT_NO } ``` # 完整源代码 https://gitee.com/cxyzy1/night-mode-demo