小编Dr.*_*dRO的帖子

撰写导航:在后台堆栈中传递参数

我已经尝试了所有可能的方法,看起来没有找到解决方案。

我正在使用带有撰写屏幕的全撰写应用程序,并使用撰写导航在此屏幕之间导航,我有一个场景,我以这种方式进一步导航

屏幕 A > 屏幕 B1 >..> 屏幕 BN > 屏幕 C

现在,在完成屏幕 C 上的功能后,我想弹回屏幕 A,但这次带有一个可选参数,例如:成功

我这样做是为了导航到 A:

val route = "ScreenA?arg={arg}"

// navigating like this
navController.navigate("ScreenA")


// handling
composable(route, arguments = listOf(navArgument("arg") { nullable = true })){
  ScreenA()
}
Run Code Online (Sandbox Code Playgroud)

现在,为了从我所在的位置弹回到 ScreenA,我已经这样做了:

navController.popBackStack(
                route = route,
                inclusive = false
            )
Run Code Online (Sandbox Code Playgroud)

我现在想在返回时发送参数。我尝试将路线添加为

 ScreenA?arg=success
Run Code Online (Sandbox Code Playgroud)

这在 popBackStack 函数中不起作用,它检查路由的哈希码

popBackStack(createRoute(route).hashCode(), inclusive, saveState)
Run Code Online (Sandbox Code Playgroud)

在这种情况下我的导航失败

我也尝试过将参数设置为后退堆栈条目,但由于它可能是中间的 N Screen,因此无法工作。需要了解我哪里做错了或者是否有办法做到这一点?

android android-jetpack-compose jetpack-compose-navigation

10
推荐指数
1
解决办法
5462
查看次数

Android设计库:SwipeRefreshLayout不会检测到在CollapsingToolbarLayout上滑动

在我的应用程序中我使用内部CollapsingToolbarLayout跟随.我想要的是检测从中扫过,但是检测到并忽略滑动.这是我的XML:NestedScrollViewSwipeRefreshLayoutSwipeRefreshLayoutCollapsingToolbarLayoutNestedScrollViewCollapsingToolbarLayout

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.SwipeRefreshLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/swipe"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsingToolbarLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <ImageView
                        android:id="@+id/profilePic"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="centerCrop"
                        android:src="@drawable/ic_split_big_profile"
                        app:layout_collapseMode="parallax"
                        app:layout_collapseParallaxMultiplier="0.7" />

                    <include
                        android:id="@+id/toolbar_layout"
                        layout="@layout/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:layout_scrollFlags="scroll|enterAlways" />

                </android.support.design.widget.CollapsingToolbarLayout>
            </android.support.design.widget.AppBarLayout>

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/transactions_scroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="500dp">
                </RelativeLayout>
            </android.support.v4.widget.NestedScrollView>

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/add_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:layout_marginBottom="@dimen/fab_margin_bottom"
                android:layout_marginRight="@dimen/fab_margin_right"
                android:onClick="addTxn"
                android:src="@drawable/ic_action_add_transaction_light"
                app:elevation="6dp"
                app:fabSize="normal" /> …
Run Code Online (Sandbox Code Playgroud)

android android-layout swiperefreshlayout android-collapsingtoolbarlayout android-appbarlayout

6
推荐指数
1
解决办法
3057
查看次数

下载时显示进度条

我想显示一个进度条,显示我的应用程序通过互联网下载一些大文件时完成的百分比.这样的事情:在此输入图像描述

android progress-bar

5
推荐指数
1
解决办法
8665
查看次数

Jetpack Compose 与 Coroutine 的 StateFlow

我在使用 StateFlow 和 Jetpack Compose 时遇到了一个奇怪的问题,我没有收到 StateFlow 中的更新值。这是我如何按照示例中的建议尝试观察 Stateflow 的代码。

@Composable
fun List(homeViewModel: HomeViewModel) {

val appState by homeViewModel.stateFlow.collectAsState()

if (appState.isLoading) {
    CircularProgressIndicator()
}
MaterialTheme {
    LazyColumn {
        items(appState.names) { name ->
            Name(name = name.name)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

}

我正确收到初始值但没有收到更新值

setContent {
  Surface(color = MaterialTheme.colors.background) {
                List(mainViewModel.homeViewModel)
      }
}
Run Code Online (Sandbox Code Playgroud)

我已经像这样在 viewModel 中定义了我的 stateFlow

internal val stateFlow = MutableStateFlow(AppState())
Run Code Online (Sandbox Code Playgroud)

我通过这个更新值

stateFlow.value = AppState(loading = false, listOf("1", "2"))
Run Code Online (Sandbox Code Playgroud)

我的 AppState Pojo

data class AppState(val names: List<Names> = emptyList(), val isLoading: Boolean = …
Run Code Online (Sandbox Code Playgroud)

android android-jetpack android-jetpack-compose

3
推荐指数
1
解决办法
1501
查看次数