Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selected item indicator color can't edit #186

Open
Aminul-Haque-Aome opened this issue Sep 17, 2023 · 1 comment
Open

Selected item indicator color can't edit #186

Aminul-Haque-Aome opened this issue Sep 17, 2023 · 1 comment

Comments

@Aminul-Haque-Aome
Copy link

In ShiftIndicatorType, How can I change selected item indicator color

@notsatria
Copy link

I also faced this problem, and the solution is by creating my own Indicator, maybe you can use mine as a reference:

@Composable
fun Indicator(
    dotCount: Int,
    currentPage: Int,
    modifier: Modifier = Modifier,
    dotSpacing: Dp = 8.dp,
    dotSize: Dp = 12.dp,
) {
    Row(
        horizontalArrangement = Arrangement.spacedBy(dotSpacing),
        verticalAlignment = Alignment.CenterVertically,
        modifier = modifier
    ) {
        for (i in 0 until dotCount) {
            val isActive = currentPage == i
            val color by animateColorAsState(targetValue =  if (isActive) Purple else DotIndicatorDefault,
                label = ""
            )
            val width by animateDpAsState(targetValue = if (isActive) dotSize * 3 else dotSize,
                label = ""
            )
            Box(
                modifier = Modifier
                    .width(width)
                    .height(dotSize)
                    .clip(CircleShape)
                    .background(color)
            )
        }
    }
}

Usage:

 Indicator(
                dotCount = pagerState.pageCount,
                currentPage = pagerState.currentPage,
                dotSpacing = 4.dp,
                modifier = Modifier
                    .align(Alignment.BottomCenter)
                    .padding(bottom = 8.dp)
                    .height(12.dp)
            )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants