Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Jetpack Compose tilted row with buttons

I'm developing an Android app in Jetpack Compose, which is basically a big form. I wanted to add a little style to it with custom buttons, but I don't really know how to make them.

What I'm trying to achieve:

Example button style

In that layout there will be 2 Buttons with a TextField in the middle. How can I tilt them so it looks like the image?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can build a custom shape like this:

class ParallelogramShape(private val angle: Float): Shape {
    override fun createOutline(
        size: Size,
        layoutDirection: LayoutDirection,
        density: Density,
    ) = Outline.Generic(
        Path().apply {
            val width = size.width - size.height / tan(angle)
            moveTo(size.width - width, 0f)
            lineTo(size.width, 0f)
            lineTo(width, size.height)
            lineTo(0f, size.height)
            lineTo(size.width - width, 0f)
        }
    )
}

And use it like this:

val border = BorderStroke(1.dp, Color.Black)
val shape = ParallelogramShape(45f)
Row(
    verticalAlignment = Alignment.CenterVertically,
    modifier = Modifier
        .padding(10.dp)
        .border(border, shape = shape)
) {
    var counter by remember { mutableStateOf(10) }
    TextButton(
        onClick = { counter -= 1 },
        shape = shape,
        border = border,
        modifier = Modifier
            .height(45.dp)
            .width(100.dp)
    ) {
        Text("-")
    }
    Text(counter.toString())
    TextButton(
        onClick = { counter += 1 },
        shape = shape,
        border = border,
        modifier = Modifier
            .height(45.dp)
            .width(100.dp)
    ) {
        Text("+")
    }
}

Result:

over 4 years ago · Santiago Trujillo Denunciar

0

This is what I was able to achieve.

enter image description here

You need two IconButton or Image for incrementing and decrementing value of the number in TextField.

Make use of Row to arrange elements horizontally.

Declare a Int to keep track of value which keeps changing with rememberSaveable.

var numberValue: Int by rememberSaveable { mutableStateOf(15) }

Now finally all elements inside a row.

    Row(
        Modifier.background(color = Color.LightGray),
        verticalAlignment = Alignment.CenterVertically
    ) {

        IconButton(onClick = { numberValue - 1 }) {
            Icon(
                imageVector = Icons.Rounded.KeyboardArrowDown,
                tint = Color.Black,
                contentDescription = null
            )
        }

        TextField(
            value = "$numberValue",
            onValueChange = {
                numberValue = it.toInt()
            },
            singleLine = true,
            keyboardOptions = KeyboardOptions(
                keyboardType = KeyboardType.Number,
            ),
            maxLines = 1,
            modifier = Modifier
                .width(60.dp)
                .background(Color.Gray, RectangleShape)
                .border(1.dp, Color.Gray, RectangleShape),

            )

        IconButton(onClick = { numberValue + 1 }) {
            Icon(
                imageVector = Icons.Rounded.KeyboardArrowUp,
                tint = Color.Black,
                contentDescription = null
            )
        }
    }
    

Replace icons which I have used in both IconButton with yours. Take take to understand all attributes in TextField .

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda