https://kotlinlang.org logo
#compose
Title
# compose
c

chanjungskim

03/07/2023, 9:02 AM
Can I create the same result without using ConstraintLayout here? https://stackoverflow.com/questions/68307564/how-to-add-drawable-to-a-text-in-compose
I am using customized checkbox like this.
here's my code:
Copy code
Button(
            onClick = {
                isPressed = !isPressed
                onNotifyButtonState.invoke(index, isPressed)
            },
            shape = buttonShape,
            border = if (isPressed) BorderStroke(1.dp, Color.PressedButtonStroke)
            else null,
            contentPadding = contentPadding,
            colors = ButtonDefaults.buttonColors(buttonColor),
            modifier = modifier,
        ) {
            Box(
                modifier = Modifier.fillMaxWidth()
            ) {
                Text(
                    text = text,
                    fontSize = fontSize,
                    color = fontColor,
                    modifier = Modifier
                        .align(Alignment.CenterStart)
                )
                Icon(
                    painter = painterResource(id = if(isPressed) R.drawable.ico_check_on else R.drawable.ico_check_nor),
                    contentDescription = null,
                    modifier = Modifier
                        .align(Alignment.CenterEnd)
                        .height(7.3.dp)
                        .width(10.3.dp)
                )
            }
        }
9 Views