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

Changing dots color individually #193

Open
ugurkuyu opened this issue Feb 16, 2024 · 1 comment
Open

Changing dots color individually #193

ugurkuyu opened this issue Feb 16, 2024 · 1 comment

Comments

@ugurkuyu
Copy link

Can we change the color of each dot individually like this? I couldn't find a way to do it.

Ekran Resmi 2024-02-16 15 13 24
@ccojocea
Copy link

ccojocea commented Aug 21, 2024

Hey, would also be interested in changing color of each dot individually (using this as xml with Java). Specifically would be interested in changing the unselected color and selected color of any single dot position. Thanks.

For anyone interested, I was able to modify the color of a specific item through my Java code like this. If you have different colors for selected/unselected, you'll need to call this in the registered viewpager listener as well as calling it after attaching it.

    private void modifyDotColor(int position, int colorRes) {
        try {
            // Access the dot (ImageView)
            ViewGroup baseViewGroup = (ViewGroup) dotsIndicator.getChildAt(0);
            ViewGroup dotViewGroup = (ViewGroup) baseViewGroup.getChildAt(position);
            View dot = dotViewGroup.getChildAt(0);
            if (dot instanceof ImageView) {
                ImageView lastDotImageView = (ImageView) dot;
                Drawable drawable = lastDotImageView.getBackground(); //DotsGradientDrawable but not needed
                ColorFilter colorFilter = new BlendModeColorFilter(
                        ContextCompat.getColor(VehicleStatusActivity.this, colorRes),
                        BlendMode.SRC_IN
                );
                drawable.setColorFilter(colorFilter);
                lastDotImageView.setBackground(drawable);
            }
        } catch (NullPointerException nullPointerException) {
            Logger.error(getClass(), nullPointerException.getMessage(), nullPointerException);
        }
    }

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