Skip to content

Commit

Permalink
fix: fixTransparentNavigationBar
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Nov 18, 2024
1 parent 18550a0 commit 03475ad
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.ActivityManager
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -67,6 +68,7 @@ class MainActivity : ComponentActivity() {
installSplashScreen()
enableEdgeToEdge()
fixTopPadding()
fixTransparentNavigationBar()
super.onCreate(savedInstanceState)
mainVm
launcher
Expand Down Expand Up @@ -188,6 +190,16 @@ fun syncFixState() {
}
}

private fun Activity.fixTransparentNavigationBar() {
// 修复在浅色主题下导航栏背景不透明的问题
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
} else {
@Suppress("DEPRECATION")
window.navigationBarColor = Color.TRANSPARENT
}
}

private fun Activity.fixTopPadding() {
// 当调用系统分享时, 会导致状态栏区域消失, 应用整体上移, 设置一个 top padding 保证不上移
var tempTop: Int? = null
Expand Down

0 comments on commit 03475ad

Please sign in to comment.