1

Please, how do I get text color of html string formatted with AndroidView() to change as the application theme changes programmatically from Light to Dark theme and vice-versa? Thanks in advance! Below are my codes:

Compose Function

 @SuppressLint("ResourceType")
@Composable
private fun CourseCardDescription(modifier: Modifier, htmlString: String) { // HTML text format

    val cxt = LocalContext.current
    val toggleColor = if (colors.isLight) {
        ResourcesCompat.getColor(cxt.resources, R.color.black, cxt.theme)
    }   else {
        ResourcesCompat.getColor(cxt.resources, R.color.white, cxt.theme)
    }
    val color by remember { mutableStateOf(toggleColor) }

    Column(
        modifier = modifier
                .padding(horizontal = LEFT_RIGHT_PADDING)
    ) {

   // .....
        AndroidView(
            modifier = modifier,
            factory = { context ->
                        TextView(context).apply {
                            layoutParams = ViewGroup.LayoutParams(
                                ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.MATCH_PARENT
                            )
                            setTextColor(color)
                            letterSpacing = 0.075f
                            setTextAppearance(R.style.CourseTextAppearance)

                        }
                      },
            update = {it.text = HtmlCompat.fromHtml(htmlStrin,HtmlCompat.FROM_HTML_MODE_COMPACT)}
        )
    }
}

Styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CourseTextAppearance">
        <item name="android:fontFamily">@font/kulim_park_regular</item>
        <item name="android:textSize">15sp</item>
<!--        <item name="android:textColor">@color/purple_700</item>-->
<!--        <item name="android:textStyle">bold</item>-->
    </style>
</resources>

0 Answers0