Wie kann man den Raum der Statusleiste bewahren? (Android 15+)

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie kann man den Raum der Statusleiste bewahren? (Android 15+)

by Anonymous » 22 Aug 2025, 08:24

Android 15 schlägt vor, EnableedGetOedge () zu verwenden, aber dies beseitigt den oberen Versatz der Statusleiste, wodurch sich der Hauptinhalt überlappt. Lassen Sie es einfach transparent und rendern Sie den Inhalt darunter.

Code: Select all

// in the MainActivity.onCreate():

enableEdgeToEdge()

// the callback will be invoked repeatedly, use this flag to only set the margin-top once
var offsetAdjusted = false

window.decorView.setOnApplyWindowInsetsListener { _, insets ->
if (!offsetAdjusted) {
offsetAdjusted = true

val top = if(Build.VERSION.SDK_INT > Def.ANDROID_10) // for android > 10
insets.getInsetsIgnoringVisibility(WindowInsets.Type.statusBars()).top
else // for android 10
view.rootWindowInsets.stableInsetTop

// the fragment container, which is a FragmentContainerView
val container = binding.root.findViewById(R.id.nav_host_fragment_activity_main)

val params = container.layoutParams as ViewGroup.MarginLayoutParams
params.topMargin = top
container.layoutParams = params
}

insets
}

Top