Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add border on bottom only in jetpack compose

I want to add border on bottom of the layout. I know i can use Divider composable but i just want to learn how to draw a border.

Currently i can add border for all sides which is not i want

Row(modifier = Modifier.border(border = BorderStroke(width = 1.dp,Color.LightGray))) {
                TextField(value = "", onValueChange = {}, modifier = Modifier.weight(1f))
                Switch(checked = true, onCheckedChange = {})
                Icon(Icons.Filled.Close, "Remove", tint = Color.Gray)
            }
like image 608
nesibeyyubov Avatar asked Jul 30 '21 14:07

nesibeyyubov


People also ask

What is spacer in jetpack compose?

In Jetpack Compose, a Spacer is a blank element that is used to create a Space between two UI elements.

Is jetpack easier to compose?

Jetpack Compose is a modern declarative UI Toolkit for Android. Compose makes it easier to write and maintain your app UI by providing a declarative API that allows you to render your app UI without imperatively mutating frontend views.

What is scaffold in jetpack compose?

Scaffold provides a slot for a floating action button. You can use the floatingActionButton slot and a FloatingActionButton : Scaffold( floatingActionButton = { FloatingActionButton(onClick = { /* ...

What is modifier jetpack compose?

Modifiers allow you to decorate or augment a composable. Modifiers let you do these sorts of things: Change the composable's size, layout, behavior, and appearance. Add information, like accessibility labels. Process user input.


Video Answer


1 Answers

You can use the drawBehind modifier.
Something like:

Row(
    modifier = Modifier
        .drawBehind {
            val strokeWidth = indicatorWidth.value * density
            val y = size.height - strokeWidth / 2

            drawLine(
                Color.LightGray,
                Offset(0f, y),
                Offset(size.width, y),
                strokeWidth
            )
        }){
    //....
}

enter image description here

like image 77
Gabriele Mariotti Avatar answered Sep 18 '22 16:09

Gabriele Mariotti