text button color change to white after button recomposition (Compose - Android)

101 Views Asked by At

This is my customButton:

@Composable
fun CustomButton(
    modifier: Modifier,
    textButton: String,
    isLoading: Boolean = false,
    onClick: () -> Unit
) {
    if (isLoading) {
        Box(
            modifier = modifier
                .background(Color.White.copy(alpha = 0.8f), shape = RoundedCornerShape(15.dp)),
            contentAlignment = Alignment.Center
        ) {
            CircularProgressIndicator(
                modifier = Modifier.size(30.dp),
                color = Color(0xFF15151A)
            )
        }
    } else {
        Button(
            modifier = modifier,
            onClick = onClick,
            colors = ButtonDefaults.buttonColors(
                containerColor = Color.White,
                contentColor = Color(0xFF15151A),
                disabledContainerColor = Color.White.copy(alpha = 0.8f),
                disabledContentColor = Color(0xFF15151A)
            ),
            shape = RoundedCornerShape(size = 15.dp),
        ) {
            Text(
                text = textButton,
                fontSize = 17.sp,
            )
        }
    }
}

the button is displayed correctly the first time (background white and text black), then loading state is activated, the CircularProgressIndicator is displayed correctly, but the problem is when the loading state finish and the button is displayed again but do it incorrectly, well the text color turn to White and is not black which is the color i am specifying to the button content.

does someone know why is this happening? and how fix it?

THIS IS A NEW UPDATE: the problem is in the dark mode of the xiaomi redmi note 8, when dark mode is on, the problem occurs, when is off nothing happen.

1

There are 1 best solutions below

0
On

It's some weird MIUI things. Try adding

  <item name="android:forceDarkAllowed">false</item>

to your themes.xml.