mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-15 19:22:26 +08:00
fix: status bar system ui
This commit is contained in:
parent
b6a05c0b92
commit
24fe493d11
|
@ -1,10 +1,14 @@
|
|||
package li.songe.gkd.composition
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.blankj.utilcode.util.BarUtils
|
||||
|
||||
open class CompositionActivity(
|
||||
private val block: CompositionActivity.(Bundle?) -> Unit,
|
||||
|
@ -30,6 +34,7 @@ open class CompositionActivity(
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
installSplashScreen()
|
||||
enableEdgeToEdge()
|
||||
fixTopPadding()
|
||||
super.onCreate(savedInstanceState)
|
||||
block(savedInstanceState)
|
||||
}
|
||||
|
@ -42,5 +47,25 @@ open class CompositionActivity(
|
|||
super.onConfigurationChanged(newConfig)
|
||||
configurationChangedHooks.forEach { f -> f(newConfig) }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
fun ComponentActivity.fixTopPadding() {
|
||||
// 当调用系统分享时, 会导致状态栏区域消失, 应用整体上移, 设置一个 top padding 保证不上移
|
||||
var tempTop: Int? = null
|
||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, windowInsets ->
|
||||
view.setBackgroundColor(Color.TRANSPARENT)
|
||||
val statusBars = windowInsets.getInsets(WindowInsetsCompat.Type.statusBars())
|
||||
if (statusBars.top == 0) {
|
||||
view.setPadding(
|
||||
statusBars.left,
|
||||
tempTop ?: BarUtils.getStatusBarHeight(),
|
||||
statusBars.right,
|
||||
statusBars.bottom
|
||||
)
|
||||
} else {
|
||||
tempTop = statusBars.top
|
||||
view.setPadding(statusBars.left, 0, statusBars.right, statusBars.bottom)
|
||||
}
|
||||
ViewCompat.onApplyWindowInsets(view, windowInsets)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user