This project showcases a segmented button UI using Jetpack Compose's SingleChoiceSegmentedButtonRow. It allows for easy navigation between different options with a visually appealing design.
- Dynamic segmented buttons with selectable options.
- Smooth transitions between different segments.
- Customizable button shapes and styles.
-
Clone the repository:
git clone https://github.com/Bhavyansh03-tech/Segmented_Buttons.git
-
Open the project in Android Studio.
-
Sync the project with Gradle files.
To use the segmented button UI in your project, integrate the SingleChoiceSegmentedButtonRow and SegmentedButton composables as shown below:
@OptIn(ExperimentalMaterial3Api::class)
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
SegmentedButtonsTheme {
var selectedIndex by remember {
mutableIntStateOf(0)
}
val options = remember {
mutableStateListOf("Music", "Movies", "Podcasts")
}
Box(
modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.Center
) {
SingleChoiceSegmentedButtonRow {
options.forEachIndexed { index, option ->
SegmentedButton(
selected = selectedIndex == index,
onClick = { selectedIndex = index },
shape = SegmentedButtonDefaults.itemShape(
index = index,
count = options.size
)
) {
Text(text = option)
}
}
}
}
}
}
}
}Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin feature/your-feature). - Create a new Pull Request.
For questions or feedback, please contact @Bhavyansh03-tech.

