【问题标题】:Screens are flashing when I navigate to them in Dark theme using Navigation-compose当我使用 Navigation-compose 在深色主题中导航到屏幕时,屏幕正在闪烁
【发布时间】:2022-11-03 01:11:57
【问题描述】:

我在我的应用程序中使用 Navigation-Compose:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeTheme {
                val navController = rememberNavController()
                NavHost(navController = navController, startDestination = Screens.Dashboard.title) {
                    composable(Screens.Dashboard.title) {
                        DashboardScreen(navController)
                    }
                    composable(
                        Screens.Section.title, arguments = listOf(
                            navArgument(LINK) {
                                type = AssetParamType()
                            }
                        )
                    ) {
                        SectionDetailsScreen(navController)
                    }
                }
            }
        }
    }

我在每个屏幕上都有一个单独的 appBar,例如:

@Composable
fun DashboardScreen(
    navController: NavHostController,
    viewModel: DashboardViewModel = hiltViewModel()
) {
    Scaffold(
        topBar = {
            TopAppBar(
                title = {
                    Box(
                        contentAlignment = Alignment.Center,
                        modifier = Modifier.fillMaxSize()
                    ) {
                        Text(text = stringResource(id = R.string.label_dashboard))
                    }
                },
                elevation = 8.dp,
                modifier = Modifier.clip(
                    RoundedCornerShape(bottomStart = 18.dp, bottomEnd = 18.dp)
                )
            )
        },
        content = {
            Content(viewModel = viewModel) { dashboard ->
                VerticalCollection(dashboard) { link ->
                    val json = Uri.encode(Gson().toJson(link))
                    navController.navigate(
                        Screens.Section.title.replace
                            ("{${LINK}}", json)
                    )
                }
            }
        })
}

当我在深色主题中导航它们时,屏幕正在闪烁。关闭深色主题时,appBar 上会出现小闪烁。如何解决?

我的项目的源代码可以在这里找到:https://github.com/alirezaeiii/Navigation-Compose

附录:

我发现如果我们使用此链接中所示的伴奏库:TopAppBar flashing when navigating with Compose Navigation 闪烁问题将得到解决,但必须使用伴奏。

【问题讨论】:

    标签: android navigation-compose


    【解决方案1】:

    我在不使用伴奏库(并覆盖动画效果)的情况下解决了这个问题。

    您是否确保您的 AppTheme 从您申请的 manifest.xml 使用 DayNight

    默认情况下,您的项目可能使用:
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    您可以将其替换为:
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      • 2017-07-13
      • 2019-07-08
      相关资源
      最近更新 更多