HideStatusBar
This commit is contained in:
parent
e261be48f0
commit
18e7db808a
1 changed files with 36 additions and 0 deletions
|
|
@ -7,17 +7,53 @@ import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import org.koin.androidx.compose.koinViewModel
|
import org.koin.androidx.compose.koinViewModel
|
||||||
|
import androidx.core.view.WindowCompat
|
||||||
|
import android.view.WindowManager
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
hideSystemBar()
|
||||||
|
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
val sharedViewModel: SharedViewModel = koinViewModel()
|
val sharedViewModel: SharedViewModel = koinViewModel()
|
||||||
App(sharedViewModel = sharedViewModel)
|
App(sharedViewModel = sharedViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private fun hideSystemBar() {
|
||||||
|
// Pour les versions d'Android plus récentes (API 30+)
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
||||||
|
val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
|
||||||
|
|
||||||
|
// Cacher les barres système
|
||||||
|
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
||||||
|
|
||||||
|
// Définir le comportement des barres système pour le mode immersif
|
||||||
|
// BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE: Les barres apparaissent temporairement
|
||||||
|
// après un balayage et disparaissent ensuite. C'est le comportement le plus courant
|
||||||
|
// pour le mode immersif.
|
||||||
|
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
} else {
|
||||||
|
// Pour les versions d'Android plus anciennes (API < 30)
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.decorView.systemUiVisibility = (
|
||||||
|
android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY // Rend le mode immersif "collant"
|
||||||
|
or android.view.View.SYSTEM_UI_FLAG_FULLSCREEN // Cache la barre d'état
|
||||||
|
or android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // Cache la barre de navigation
|
||||||
|
or android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
or android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
or android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
)
|
||||||
|
// Utiliser FLAG_LAYOUT_NO_LIMITS pour s'assurer que le contenu s'étend derrière la barre de navigation si elle réapparaît temporairement
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue