Skip to content

Commit

Permalink
add Context.isDarkMode
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCheen committed May 26, 2022
1 parent 29b3d12 commit c38715a
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.net.ConnectivityManager
import android.os.Build
import android.view.View
Expand Down Expand Up @@ -92,4 +93,12 @@ fun Context.isNetworkAvailable(): Boolean {
return manager.activeNetworkInfo!!.isAvailable
}
return false
}

/**
* 判断当前是否是暗黑模式
*/
fun Context.isDarkMode(): Boolean {
val uiMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return uiMode == Configuration.UI_MODE_NIGHT_YES
}

0 comments on commit c38715a

Please sign in to comment.