webview 的深色主题在 AndroidView Jetpack compose 中不起作用

问题描述 投票:0回答:1

Webview 的深色主题在 AndroidView Jetpack compose 中不起作用。

RichEditor 扩展 webview。

没有错误。根本无法应用深色主题来查看

implementation 'jp.wasabeef:richeditor-android:2.0.0'
@Composable
fun Webview{
  AndroidView(
        factory = { context ->
            RichEditor(context).apply {
                setEditorHeight(40)
                setPadding(10, 10, 10, 10)
                loadCSS("file:///android_asset/style.css")
                if (isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) {
                    WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, true)
                }
                setOnTextChangeListener {
                    scope.launch {

                    }
                }
            }
        },
        update = {
        },
        )
}
android view android-jetpack-compose android-webview editor
1个回答
0
投票

它不起作用,因为

RichEditor
(或
WebView
)本身不支持黑暗模式。您可以使用公共函数根据深色主题调整其外观:


@Composable
fun Webview() {

    //Colors based on system theme
    val isDark = isSystemInDarkTheme()
    val textColor = remember(key1 = isDark) { if (isDark) Color.White else Color.Black }
    val backgroundColor = remember(key1 = isDark) { if (isDark) Color.Black else Color.White }

    AndroidView(
        factory = { context ->
            RichEditor(context).apply {
                setEditorHeight(40)
                setPadding(10, 10, 10, 10)
                loadCSS("file:///android_asset/style.css")
                //Sets background color
                this.setEditorBackgroundColor(backgroundColor.toArgb())
                //Sets text color                
                this.setEditorFontColor(textColor.toArgb())
                if (isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) {
                    WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, true)
                }
                setOnTextChangeListener {
                    scope.launch {

                    }
                }
            }
        },
        update = {

        },
    )
© www.soinside.com 2019 - 2024. All rights reserved.