Add the dependency below to your module's build.gradle
file:
dependencies {
implementation "com.github.ocetin00:ToggleTab:1.0.0"
}
@Preview
@Composable
fun ToggleTabPreview1() {
Row(
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.padding(top = 10.dp)
.fillMaxWidth()
) {
ToggleTab(modifier = Modifier.fillMaxWidth(0.6f),titleList = listOf("Male", "Famele"), onTabSelected = {})
}
}
You can create toggle-tab with selected color,container color and text style
Keep reading for more details
@Preview
@Composable
fun ToggleTabPreview2() {
var selectedPageIndex by remember {
mutableStateOf(1)
}
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.White)
) {
Row(
modifier = Modifier
.padding(vertical = 20.dp)
.fillMaxWidth()
.background(Color.White), horizontalArrangement = Arrangement.Center
) {
ToggleTab(
modifier = Modifier
.fillMaxWidth(fraction = 0.9f)
.clip(ShapeDefaults.ExtraLarge),
onTabSelected = { index ->
selectedPageIndex = index
},
titleList = listOf("First", "Second", "Third"),
tabItemTextStyle = TextStyle.Default.copy(
fontSize = 12.sp,
fontWeight = FontWeight.Bold
)
)
}
var backgroundColor: Color = when (selectedPageIndex) {
0 -> Color.Green
1 -> Color.Magenta
2 -> Color.Cyan
else -> {
Color.Green
}
}
Column(
modifier = Modifier
.padding(20.dp)
.fillMaxSize()
.background(backgroundColor)
) {
}
}
}
follow me on GitHub for my next creations!
Copyright 2019 ocetin00 (Oğuzhan Çetin)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.