Android

์•ˆ๋“œ๋กœ์ด๋“œ Android Jetpack Compose Status Bar ์ƒํƒœ๋ฐ” ์ƒ‰์ƒ ๋ณ€๊ฒฝํ•˜๊ธฐ

๋…ธ๋ฃจ๋ฃฝ 2025. 1. 24. 18:23

 

์•ˆ๋“œ๋กœ์ด๋“œ์—์„œ Status Bar(์ƒํƒœ๋ฐ”)์˜ ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์€ ๋งค์šฐ ๋งค์šฐ ํ”ํžˆ ์žˆ๋Š” ์ผ์ด๋‹ค..

(์•„๋งˆ ๋Œ€๋ถ€๋ถ„์˜ ์•ฑ์ด ๊ทธ๋Ÿฌ์ง€ ์•Š์„๊นŒ?)

 

์ด๋ฒˆ์— Jetpack Compose๋ฅผ ๋ฐฐ์šฐ๋ฉด์„œ ์•ฑ ์ „์ฒด์˜ Status Bar ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝํ•ด์•ผ ํ–ˆ๋‹ค.

์ตœ๊ทผ ์•ˆ๋“œ๋กœ์ด๋“œ์—์„œ๋Š” EdgeToEdge ๋ฐฉ๋ฒ•์„ ๊ถŒ์žฅํ•˜๋Š” ๊ฒƒ ๊ฐ™์ง€๋งŒ,

๋‚˜๋Š” ์•„์ง ์ด ๋ฐฉ๋ฒ•์— ์ต์ˆ™ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ๋ชจ์ƒ‰ํ–ˆ๋‹ค!

(ํ•˜์ง€๋งŒ ์›ฌ๋งŒํ•˜๋ฉด EdgeToEdge๋ฅผ ์ด์šฉํ•˜๊ธธ ๋ฐ”๋žŒ!)


1. build.gradle.kts์— Accompanist ์˜์กด์„ฑ ์ถ”๊ฐ€

implementation ("com.google.accompanist:accompanist-systemuicontroller:0.27.0")

 

Goggle Accompanist๋Š” Google์—์„œ JetpackCompose ๊ฐœ๋ฐœ์— ํ•„์š”ํ•˜์ง€๋งŒ,

์•„์ง์€ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š”(?) ๊ธฐ๋Šฅ๋“ค์„ ์ œ๊ณตํ•ด์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ชจ์Œ์ด๋‹ค.

Accompanist๋ฅผ ๋‘˜๋Ÿฌ๋ณด๋ฉด Permissions, Drawable Painter ๋“ฑ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์ด ์ œ๊ณต๋˜๊ณ  ์žˆ๋‹ค.

 

2. ๐Ÿ“ theme → Theme.kt

๋‚˜๋Š” ์•ฑ ์ „์ฒด์˜ Status Bar ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— Theme ํŒŒ์ผ์—์„œ ์ƒ‰์ƒ์„ ์„ค์ •ํ•ด ์ฃผ๊ธฐ๋กœ ํ–ˆ๋‹ค.

@Composable
fun ComposeRecipeAppTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    dynamicColor: Boolean = true,
    content: @Composable () -> Unit
) {

...

    val systemUiController = rememberSystemUiController()
    if (darkTheme) {
        systemUiController.setSystemBarsColor(
            color = Color.Transparent // ๋‹คํฌํ…Œ๋งˆ์ผ๋•Œ Status Bar ์ƒ‰์ƒ
        )
    } else {
        systemUiController.setSystemBarsColor(
            color = Color.White // ๋ผ์ดํŠธํ…Œ๋งˆ์ผ๋•Œ Status Bar ์ƒ‰์ƒ
        )
    }
...

}

 

๊ทธ๋Ÿผ ์ด๋ ‡๊ฒŒ Recipe App ์ „์ฒด์˜ Status Bar๊ฐ€ ํฐ์ƒ‰์œผ๋กœ ๊น”๋”ํ•˜๊ฒŒ ๋œ๋‹ค. - ฬ—ฬ€ โธœีž•๐–ฅฆ•ีžโธ ฬ–ฬ-

 

(+)

์•„์ง Compose์— ์ต์ˆ™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค . . .

์ž˜๋ชป๋œ ์ •๋ณด๊ฐ€ ์žˆ์œผ๋ฉด, ๋Œ“๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ! ๐Ÿฅฐ

 

Reference

https://github.com/google/accompanist

 

GitHub - google/accompanist: A collection of extension libraries for Jetpack Compose

A collection of extension libraries for Jetpack Compose - google/accompanist

github.com