[英]How to Make Navigation Bar Transparent in Android Jetpack Compose?
I want to make the navigation bar transparent in Jetpack Compose.我想让 Jetpack Compose 中的导航栏透明。
This is the code:这是代码:
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.core.view.WindowCompat
import com.google.accompanist.systemuicontroller.rememberSystemUiController
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// app UI is expanded to system bars
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
// this is also not working
// window.navigationBarColor = android.graphics.Color.TRANSPARENT
setContent {
YourProjectNameTheme {
val systemUiController = rememberSystemUiController()
SideEffect {
// set transparent color so that our image is visible
// under the status bar
systemUiController.setStatusBarColor(color = Color.Transparent)
// not working
systemUiController.setNavigationBarColor(color = Color.Transparent)
}
Surface(
modifier = Modifier
.fillMaxSize(),
color = MaterialTheme.colors.background
) {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.navigationBarsPadding() // adds padding below
) {
items(count = 4) {
Image(
painter = painterResource(id = R.drawable.squirrel),
contentDescription = "Squirrel",
contentScale = ContentScale.FillWidth,
modifier = Modifier.fillMaxWidth()
)
}
}
}
}
}
}
}
Here is the output:这是输出:
The navigation bar is not 100% transparent.导航栏不是 100% 透明的。 I'm using the system ui controller:
我正在使用系统 ui 控制器:
implementation "com.google.accompanist:accompanist-systemuicontroller:0.28.0"
Other colors like Red, Green (fully opaque) are working.其他颜色如红色、绿色(完全不透明)正在工作。 But I cannot set trasparent color.
但是我不能设置透明颜色。 Anyone knows the solution?
有人知道解决方案吗?
val systemUiController = rememberSystemUiController()
SideEffect {
systemUiController.setNavigationBarColor(
// setColor Here
color = Color.Magenta,
darkIcons = false
)
}
set color on Color.Magenta在 Color.Magenta 上设置颜色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.