【问题标题】:How to use both color and image as background with Jetpack Compose?如何在 Jetpack Compose 中同时使用颜色和图像作为背景?
【发布时间】:2021-07-27 16:23:46
【问题描述】:

除了颜色之外,我还想为我的屏幕使用背景颜色(比如蓝色)和图像(以添加效果)。我该怎么做?

目前我在做:

Box(
    modifier = Modifier.fillMaxSize().background(color = MaterialTheme.colors.background)) {
.
.
.
.
.
}

但在“背景”中没有指定图像的选项。 我该怎么做?

【问题讨论】:

  • 您可以在 Box 中添加图像。你想要一个在图像上带有渐变的图像吗?

标签: android background android-jetpack-compose


【解决方案1】:
Box(modifier = Modifier.fillMaxSize().background(color = MaterialTheme.colors.background)) {
  Image(
      painter = painterResource(R.drawable.header),
      contentDescription = null,
      modifier = Modifier
           .fillMaxSize(),
      contentScale = // Your contentscale
  )
}

【讨论】:

    猜你喜欢
    • 2022-06-15
    • 2023-02-13
    • 2021-01-30
    • 2022-11-01
    • 2022-11-06
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2022-08-18
    相关资源
    最近更新 更多