MainActivity.kt
// Scaffold
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
DefaultTheme {
MyScaffoldEx()
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MyScaffoldEx(){
Scaffold(
topBar = {
MyTopBar()
},
floatingActionButton = {
MyFloatingActionButton()
},
bottomBar = {
MyBottomBar()
}
) { paddingValues ->
Surface(modifier = Modifier
.fillMaxSize()
.padding(paddingValues)) {
Text(text = "this is content")
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MyTopBar(){
TopAppBar(
title = {
Text(text = "Main")
},
navigationIcon = {
IconButton(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Add, contentDescription = "add")
}
},
actions = {
Button(onClick = { /*TODO*/ }) {
Text(text = "Btn")
}
},
colors = TopAppBarDefaults.smallTopAppBarColors(Color.Red)
)
}
@Composable
fun MyFloatingActionButton() {
FloatingActionButton(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Menu, contentDescription = "Menu")
}
}
@Composable
fun MyBottomBar(){
BottomAppBar(
containerColor = Color.Red
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
IconButton(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Home, contentDescription = "home")
}
IconButton(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Favorite, contentDescription = "Favorite")
}
IconButton(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Settings, contentDescription = "Settings")
}
}
}
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
DefaultTheme {
MyScaffoldEx()
}
}