NoSuchMethodError setDecorFitsSystemWindows when I use window?.setDecorFitsSystemWindows(true)

574 Views Asked by At

I want to make my Activity top to the screen, and the StatusBar transparent, so I write this code:

window?.setDecorFitsSystemWindows(true)
window?.statusBarColor = Color.TRANSPARENT

My targetVersion is 30 My appcompat version is 1.3.0

but when I run it , I got Exception like this enter image description here

1

There are 1 best solutions below

0
Zain On

So, to remove this exception you need to use the compatible version of the window (i.e. WindowCompat)

So replace:

window?.setDecorFitsSystemWindows(true)

With:

WindowCompat.setDecorFitsSystemWindows(window, true)