package com.example.appcent.ui import androidx.appcompat.app.AppCompatActivity import…
- User
package com.example.appcent.ui
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.compose.material.Scaffold import androidx.compose.material.Text import androidx.compose.material.TopAppBar import androidx.compose.runtime.Composable import com.example.appcent.R
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) }
code@Composable fun FirstScreen() { Scaffold( topBar = { TopAppBar( title = { Text("First Screen") } ) } ) { // Add your UI components here Text(text = "This is the first screen") } } @Composable fun SecondScreen() { Scaffold( topBar = { TopAppBar( title = { Text("Second Screen") } ) } ) { // Add your UI components here Text(text = "This is the second screen") } }}, i have this 2 composable functions. I want a bottom app bar with 2 icons. I am using jetpack compose in the project. I want first icon will open the firstScreen composable and other icon will open secondScreen composable.
- Assistant
To achieve this, you can create a
BottomAppBarwith two icons, and switch between the screens using arememberstate. Here's an example to help you understand how to do this:- First, import all necessary dependencies at the beginning of your Kotlin file: