Fix system bars color on Android 13 and below

This commit is contained in:
iKirby 2024-09-15 12:43:50 +08:00 committed by GitHub
parent 440aaa9a1a
commit e43ad4860f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 69 additions and 19 deletions

View file

@ -1,11 +1,14 @@
package io.nekohasekai.sfa.ui.shared
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.view.WindowCompat
import androidx.viewbinding.ViewBinding
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.color.DynamicColors
@ -15,8 +18,7 @@ import io.nekohasekai.sfa.ui.MainActivity
import io.nekohasekai.sfa.utils.MIUIUtils
import java.lang.reflect.ParameterizedType
abstract class AbstractActivity<Binding : ViewBinding>() :
AppCompatActivity() {
abstract class AbstractActivity<Binding : ViewBinding> : AppCompatActivity() {
private var _binding: Binding? = null
internal val binding get() = _binding!!
@ -26,10 +28,17 @@ abstract class AbstractActivity<Binding : ViewBinding>() :
DynamicColors.applyToActivityIfAvailable(this)
val colorSurfaceContainer =
getAttrColor(com.google.android.material.R.attr.colorSurfaceContainer)
window.statusBarColor = colorSurfaceContainer
window.navigationBarColor = colorSurfaceContainer
// Set light navigation bar for Android 8.0
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
val nightFlag = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
if (nightFlag != Configuration.UI_MODE_NIGHT_YES) {
val insetsController = WindowCompat.getInsetsController(
window,
window.decorView
)
insetsController.isAppearanceLightNavigationBars = true
}
}
_binding = createBindingInstance(layoutInflater).also {
setContentView(it.root)

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base.V23" />
<style name="AppTheme.Base.V23.Night" parent="AppTheme.Base.V23">
<item name="android:windowLightStatusBar">false</item>
</style>
</resources>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base.V26.Night" />
<style name="AppTheme.Base.V26.Night" parent="AppTheme.Base.V26">
<item name="android:windowLightStatusBar">false</item>
</style>
</resources>

View file

@ -1,8 +0,0 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="m">false</item>
</style>
</resources>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base.V23" />
<style name="AppTheme.Base.V23" parent="AppTheme.Base">
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">?attr/colorSurfaceContainer</item>
</style>
</resources>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base.V26" />
<style name="AppTheme.Base.V26" parent="AppTheme.Base.V23">
<item name="android:navigationBarColor">?attr/colorSurfaceContainer</item>
</style>
</resources>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base.V27" />
<style name="AppTheme.Base.V27" parent="AppTheme.Base.V26">
<item name="android:windowLightNavigationBar">true</item>
</style>
</resources>

View file

@ -1,9 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="android:windowLightNavigationBar" tools:targetApi="m">true</item>
</style>
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="Theme.Material3.DayNight.NoActionBar">
<item name="bottomSheetDialogTheme">@style/BottomSheetDialogTheme</item>