Jetpack Compose中按钮上的背景颜色 [英] background color on Button in Jetpack Compose

查看:447
本文介绍了Jetpack Compose中按钮上的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Button(backgroundColor = Color.Yellow) {
       Row {
            Image(asset = image)
            Spacer(4.dp)
            Text("Button")
           }
    }

我无法弄清楚为什么我不能在Compose Layout代码实验室上使用的按钮上使用背景色在image()中的backgroundColor和asset中存在问题.请帮我弄清楚如何使用Buton,我还是新手

I can not figure out why I can't use background color on Button I followed on Compose Layout codelabs there is a problem in backgroundColor and asset in Image(). Please help me figure out how to use Buton, I'm still new

推荐答案

使用 ButtonDefaults (在1.0.0-alpha09到alpha11中可用)

Use ButtonDefaults which is available in 1.0.0-alpha09 to alpha11

Button(
   onClick = {},
   colors = ButtonDefaults.buttonColors(backgroundColor = Color.Yellow)
) {
   /**/
}

旧版本

Button backgroundColor 1.0.0-alpha7

使用以下内容代替

Button(
   onClick = {},
   colors = ButtonConstants.defaultButtonColors(backgroundColor = Color.Yellow)
) {
   /**/
}

这篇关于Jetpack Compose中按钮上的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆