Jetpack Compose의 버튼 배경색

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

Compose Layout codelabs에서 배경색을 사용할 수없는 이유를 알 수 없습니다. Image ()의 backgroundColor 및 asset에 문제가 있습니다. Buton 사용법을 알아 내도록 도와주세요. 아직 처음입니다.

답변

4 Elye Nov 22 2020 at 18:38

backgroundColor에 대한 Button더 이상 작동에1.0.0-alpha7

대신 아래 사용

Button(
   onClick = {},
   colors = ButtonConstants.defaultButtonColors(backgroundColor = Color.Yellow)
) {
   /**/
}
GabrieleMariotti Oct 16 2020 at 00:01

당신이 사용할 수있는:

val image =  imageResource(R.drawable.xxx)

Button(
        onClick = {  },
        backgroundColor = Color.Yellow) {
    Row {
        Image(asset = image)
        Spacer(Modifier.preferredSize(4.dp))
        Text("Button")
    }
}
OussemaAroua Dec 19 2020 at 06:28

은 ButtonConstants.defaultButtonColor에 사용되지 않습니다 1.0.0-alpha09사용 :

 colors = ButtonDefaults.buttonColors(backgroundColor = Color.Yellow)