admin管理员组

文章数量:1124537

Is there any top app bar composable in Android with Jetpack Compose where the value of the 'title' parameter is not mandatory?

I asked an LLM, and it suggested using SmallTopAppBar(), but I am facing an issue with its import statement: import androidxpose.material3.SmallTopAppBar. The LLM also recommended adding a dependency: implementation("androidxpose.material3:material3:1.3.1"). I synced my Gradle file with this dependency, but nothing works. The problem shown in studio was: Unresolved Reference

Please help...

Is there any top app bar composable in Android with Jetpack Compose where the value of the 'title' parameter is not mandatory?

I asked an LLM, and it suggested using SmallTopAppBar(), but I am facing an issue with its import statement: import androidx.compose.material3.SmallTopAppBar. The LLM also recommended adding a dependency: implementation("androidx.compose.material3:material3:1.3.1"). I synced my Gradle file with this dependency, but nothing works. The problem shown in studio was: Unresolved Reference

Please help...

Share Improve this question edited yesterday Rokata 1,23114 silver badges34 bronze badges asked 2 days ago blowingMyBody...blowingMyBody... 33 bronze badges New contributor blowingMyBody... is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 1

There is no SmallTopAppBar Composable, this is just the name of this kind of top app bar, which maps to the TopAppBar Composable.

You will continuously stumble across this type of inaccuracies if you solely rely on LLM. I would suggest that you make yourself familiar with the Jetpack Compose documentation:

  • App Bars Documentation
  • Material3 Composables
  • Jetpack Compose Basics Codelab

Also, if you generate a project using the Jetpack Compose Template in Android Studio, it will generate a project that has all important dependencies set up already, including the material3 dependency:

Besides that, you can just leave the title parameter empty for all sorts of TopAppBars:

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TopAppBarDemo() {
    Column(
        modifier = Modifier.fillMaxWidth()
    ) {
        LargeTopAppBar(
            title = {},
            navigationIcon = {
                Icon(imageVector = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "")
            },
            actions = {
                Icon(Icons.Default.MoreVert, "")
            }
        )
        MediumTopAppBar(
            title = {},
            navigationIcon = {
                Icon(imageVector = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "")
            },
            actions = {
                Icon(Icons.Default.MoreVert, "")
            }
        )
        CenterAlignedTopAppBar(
            title = {},
            navigationIcon = {
                Icon(imageVector = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "")
            },
            actions = {
                Icon(Icons.Default.MoreVert, "")
            }
        )
        TopAppBar(
            title = {},
            navigationIcon = {
                Icon(imageVector = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "")
            },
            actions = {
                Icon(Icons.Default.MoreVert, "")
            }
        )
    }
}

Output:

本文标签: I am having a problem with the Top App Bar in Android development using Jetpack ComposeStack Overflow