Dynamic colors [2/2]

This commit is contained in:
Rahul Patel
2024-09-02 03:23:24 +05:30
parent 3546ed8a54
commit 20b507b029
12 changed files with 120 additions and 80 deletions

View File

@@ -19,27 +19,12 @@
package com.aurora.extensions
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import androidx.core.graphics.ColorUtils
import androidx.core.view.WindowInsetsControllerCompat
import androidx.appcompat.app.AppCompatDelegate
@Suppress("DEPRECATION")
private fun AppCompatActivity.setSystemBarConfiguration(light: Boolean) {
WindowInsetsControllerCompat(this.window, this.window.decorView.rootView).apply {
// Status bar color
if (isMAndAbove()) {
isAppearanceLightStatusBars = light
} else {
// Add a semi-transparent black color to the status bar & navigation bar
window.statusBarColor = ColorUtils.setAlphaComponent(Color.BLACK, 120)
window.navigationBarColor = ColorUtils.setAlphaComponent(Color.BLACK, 120)
}
// Navigation bar color
if (isOMR1AndAbove()) {
isAppearanceLightNavigationBars = light
window.navigationBarColor = getStyledAttributeColor(android.R.attr.colorBackground)
}
fun setAppTheme(themeStyle: Int) {
when (themeStyle) {
1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
else -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}