Home > OS >  Divider in compose material 3
Divider in compose material 3

Time:08-02

I want to add a horizontal divider below the top bar like this:

enter image description here

I am using Material 3. but the Divider can not be resolved. here are my dependencies:

 dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation 'androidx.compose.material3:material3:1.0.0-alpha01'
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}

And here are my codes:

 Scaffold(
        topBar = {
            SmallTopAppBar(
                navigationIcon = {
                    IconButton(
                        onClick = {}) {
                        Icon(
                            imageVector = Icons.Default.ArrowBack,
                            contentDescription = "Back",
                            tint = Color.Black
                        )
                    }
                },
                title = {
                    Text(
                        text = "",
                        color = MaterialTheme.colorScheme.onPrimary
                    )
                },
            )
        }
    ) {
        Box {
            Divider(color = Color.Gray, thickness = 1.dp)

        }

    }

But as I mentioned above Divider is the unresolved reference:

enter image description here

CodePudding user response:

Please upgrade to:

    implementation 'androidx.compose.material3:material3:1.0.0-alpha15'
  • Related