🌈 Create new beautiful Compose Gradients with our new wesite ->

Gradient Button

Alex Styl
Kotlin
import androidx.compose.animation.core.tween
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.style.animate
import androidx.compose.foundation.style.hovered
import androidx.compose.foundation.style.pressed
import androidx.compose.foundation.style.rememberUpdatedStyleState
import androidx.compose.foundation.style.styleable
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.shadow.Shadow
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.composeunstyled.UnstyledButton

@Preview
@Composable
fun GradientButton() {
    val interactionSource = remember { MutableInteractionSource() }
    val styleState = rememberUpdatedStyleState(interactionSource)

    UnstyledButton(
        onClick = { /* TODO */ },
        interactionSource = interactionSource,
        modifier = Modifier
            .padding(10.dp)
            .styleable(styleState) {
                shape(RoundedCornerShape(40.dp))
                background(
                    Brush.linearGradient(
                        colors = listOf(Color(0xFF00C6FF), Color(0xFF0072FF)),
                    ),
                )
                dropShadow(
                    Shadow(
                        0.dp,
                        Color(0xFF0072FF),
                        0.dp,
                        DpOffset(0.dp, 4.dp),
                        1f,
                        BlendMode.SrcOver
                    )
                )

                hovered {
                    animate(tween(durationMillis = 200)) {
                        dropShadow(
                            Shadow(
                                0.dp,
                                Color(0xFF0072FF),
                                0.dp,
                                DpOffset(0.dp, 6.dp),
                                1f,
                                BlendMode.SrcOver
                            )
                        )
                    }
                }
                pressed {
                    animate(tween(durationMillis = 200)) {
                        translationY(0f)
                        background(
                            Brush.linearGradient(
                                colors = listOf(Color(0xFF0072FF), Color(0xFF00C6FF)),
                            ),
                        )
                        dropShadow(Shadow(0.dp))
                    }
                }
            },
    ) {
        BasicText(
            text = "BUTTON",
            style = TextStyle(
                color = Color.White,
                fontSize = 24.sp,
                fontWeight = FontWeight.Bold,
            ),
            modifier = Modifier.padding(horizontal = 28.dp, vertical = 12.dp),
        )
    }
}

Dependencies

implementation("androidx.compose.foundation:foundation")
implementation("com.composables:composeunstyled")

MIT License

MIT License

Copyright (c) 2026 Alex Styl

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.