background color on Button in Jetpack Compose

假装没事ソ 提交于 2020-12-15 03:42:41

问题


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

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


回答1:


The backgroundColor for Button no longer work in 1.0.0-alpha7

Use the below instead

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



回答2:


You can use:

val image =  imageResource(R.drawable.xxx)

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


来源:https://stackoverflow.com/questions/64376333/background-color-on-button-in-jetpack-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!