Created
May 8, 2023 09:37
-
-
Save Esarve/98f8baaa9b73540800fc208dc013dc60 to your computer and use it in GitHub Desktop.
Segmented Button Usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
MaterialSegmentedButtonTheme { | |
// A surface container using the 'background' color from the theme | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colorScheme.background | |
) { | |
Column { | |
SegmentedButton( | |
items = listOf( | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Settings, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Foo") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 1 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Delete, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Bar") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 2 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Add, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Baz") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 3 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Refresh, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Quax") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 4 ") | |
} | |
), | |
), | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(horizontal = 8.dp, vertical = 32.dp) | |
) | |
SegmentedButton( | |
items = listOf( | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Settings, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Foo") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 1 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Delete, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Bar") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 2 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Add, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Baz") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 3 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Refresh, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Quax") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 4 ") | |
} | |
), | |
), | |
showIconForSelectedOnly = true, | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(horizontal = 8.dp, vertical = 32.dp) | |
) | |
SegmentedButton( | |
items = listOf( | |
SegmentedButtonItem( | |
title = { Text(text = "Foo") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 1 ") | |
} | |
), | |
SegmentedButtonItem( | |
title = { Text(text = "Bar") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 2 ") | |
} | |
), | |
SegmentedButtonItem( | |
title = { Text(text = "Baz") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 3 ") | |
} | |
), | |
SegmentedButtonItem( | |
title = { Text(text = "Qux") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 4 ") | |
} | |
), | |
), | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(horizontal = 8.dp, vertical = 32.dp) | |
) | |
SegmentedButton( | |
items = listOf( | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Settings, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Foo") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 1 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Delete, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Bar") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 2 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Add, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Baz") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 3 ") | |
} | |
), | |
SegmentedButtonItem( | |
leadingIcon = { | |
Icon( | |
Icons.Rounded.Refresh, | |
contentDescription = "" | |
) | |
}, | |
title = { Text(text = "Quax") }, | |
onClick = { | |
Log.d("TAG", "onCreate: Selected 4 ") | |
} | |
), | |
), | |
color = SegmentedButtonDefaults.segmentedButtonColors( | |
containerColor = MaterialTheme.colorScheme.tertiaryContainer, | |
selectedContainerColor = MaterialTheme.colorScheme.tertiary | |
), | |
cornerRadius = SegmentedButtonDefaults.segmentedButtonCorners(40) | |
, | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(horizontal = 8.dp, vertical = 32.dp) | |
) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment