Search code examples
androidandroid-jetpack-composematerial-design

how to set overscroll color in material 3 (android jetpack compose)?


Not sure if it's called overscroll... I'm talking about that effect appearing when we try to scroll beyond the limit.

  1. what's the name of that?
  2. how do I change the color of it?

I've tried reading the docs, but I can't find much since I don't know the actual name of this feature

This is what I'm expecting to see:

blue overscroll (?) example


Solution

  • According to this answer, you can wrap the affected elements in the CompositionLocalProvider

    MaterialTheme(
        colorScheme = colorScheme,
        typography = Typography
    ){
        CompositionLocalProvider(
            LocalOverscrollConfiguration provides OverscrollConfiguration(
                glowColor = Color.Red
            ),
            content = content
        )
    }
    

    The glowColor will only be applied if the overscroll platform effect is glow.

    From andoid 12, it was changed to stretch so the glowColor will just be ignored