android-jetpack-composeandroid-jetpackandroid-jetpack-compose-material3wordpress-jetpack

how to create customised silver app bar in jetpack compose


I want build a app in jetpack compose with customised app means a silver app with list. thanks in advance

jetpack compose silver app bar check here for UI


Solution

  • please check here

       @OptIn(ExperimentalMaterial3Api::class)
    @Composable
    fun TopAppBarWithScaffold() {
        val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
        Scaffold(
            modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
            topBar = { LargeTopAppBar(scrollBehavior = scrollBehavior) }
        ) { padding ->
            LazyColumn(
                modifier = Modifier
                    .fillMaxSize()
                    .padding(padding),
                contentPadding = PaddingValues(16.dp)
            ) {
                items(50) {
                    ListItem(
                        headlineContent = { Text(text = "Item $it") },
                        leadingContent = {
                            Icon(
                                imageVector = Icons.Default.Face,
                                contentDescription = null
                            )
                        }
                    )
                }
            }
        }
    }
    

    and LargeTopAppBar fun create

    @OptIn(ExperimentalMaterial3Api::class)
    @Composable
    fun LargeTopAppBarM3(
        scrollBehavior: TopAppBarScrollBehavior
    ) {
        LargeTopAppBar(
            scrollBehavior = scrollBehavior,
            title = {
                Text(
                    text = "Silver App bar",
                    maxLines = 1,
                    overflow = TextOverflow.Ellipsis
                )
            },
            navigationIcon = {
                IconButton(onClick = { /* do something*/ }) {
                    Icon(imageVector = Icons.Filled.Menu, contentDescription = "Open Menu")
                }
            },
            actions = {
    
                IconButton(onClick = { /* do something*/ }) {
                    Icon(imageVector = Icons.Filled.Settings, contentDescription = "Open Settings")
                }
    
            }
        )
    }