how to put button in top right most corner in jetpack compose

3.1k Views Asked by At

I do not know how to put button at top right most corner of the screen in jetpack compose.Please help me with the code?

I have added button but it is showing at the centre of the screen

2

There are 2 best solutions below

0
z.g.y On

Can you try this?

@Composable
fun MyScreen() {
    Box(
        modifier = Modifier.fillMaxSize()
    ){
        Button(
            modifier = Modifier.align(Alignment.TopEnd),
            onClick = {}
        ) {
            Text("A Button")
        }
    }
}

enter image description here

1
izmirlikezzap On
Box(){
            IconButton(
                onClick = { /* Handle settings button click */ },
                modifier = Modifier
                    .padding(9.dp)
            ) {
                Icon(
                    imageVector = Icons.Default.Settings,
                    contentDescription = "Settings"
                )
            }

        }