最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android jetpack compose - The dialog composable's decorFitsSystemWindows = false doesn't adjust for the ime keyb

programmeradmin1浏览0评论

I am using a dialog composable within a NavHost from NavGraphBuilder 2.8.4.

I have a demo project setup to pinpoint a issue within a larger project but it seems either decorFitsSystemWindows doesn't account for the insets from the keyboard in multi-window mode or that I am missing something else. The padding adjusts correctly otherwise when not in multi-window mode. I also have android:windowSoftInputMode="adjustPan" set in my app's manifest.

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
                MyScreen()
        }
    }
}

@Composable
fun MyScreen() {

    val navController = rememberNavController()

    MyElevatedPopupSurface {

        NavHost(navController = navController, startDestination = "main") {

            composable(route = "main"){
                Button(onClick = { navController.navigate("list-view") {
                    launchSingleTop = true
                } }) {
                    Text("List of inputs")
                }
            }

            dialog(
                route = "list-view",
                dialogProperties = DialogProperties(
                    usePlatformDefaultWidth = false,
                    decorFitsSystemWindows = false
                )
            ){
                Column(modifier = Modifier
                    .verticalScroll(state = rememberScrollState(), reverseScrolling = true)
                    .imePadding()
                ) {
                    for (index in 0 until 20) {
                        TextField(
                            value = "",
                            onValueChange = { /* Handle text input */ },
                            label = { Text("Input ${index + 1}") },
                            modifier = Modifier.fillMaxWidth()
                        )
                    }
                }
            }
        }
    }
}

@Composable
fun MyElevatedPopupSurface(
    modifier: Modifier = Modifier,
    content: @Composable () -> Unit
)
{
    Box(
        modifier = modifier.then(
            Modifier
                .padding(8.dp)
                .clickable {}, // intercept click events
        )
    ) {
        PopupSurface(
            elevation = 4.dp
        ) {
            content()
        }
    }
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论