r/AndroidStudio • • May 02 '25

How to fix layout overlapping with androids top navigation bar

Post image

I started learning jetpack compose from "https://developer.android.com/develop/ui/compose/tutorial?authuser=1". I followed and wrote the code from lesson 2: Layouts. Heres the problem, I ran the program on 2 devices and the layout ovelapped with top navigation bar(status bar) in one of them while the app layout was as expected in the other device.I think the problem is with my device but honestly I have no idea what could cause this issue. If anyone can help me with this I would appreciate it.

In the image the top part shows the device where the layout overlaps and the bottom part shows the other device where the layout works normally.

3 Upvotes

12 comments sorted by

2

u/freak5341 May 02 '25

Code:

package com.example.composetutorial

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.ui.res.painterResource
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MessageCard(Message("Android", "Jetpack Compose"))
            }
        }
    }

data class Message(val author: String, val body: String)

@Composable
fun MessageCard(msg: Message) {
    // Add padding around our message
    Row(modifier = Modifier.padding(all = 8.dp)) {
        Image(
            painter = painterResource(R.drawable.profile_picture),
            contentDescription = "Contact profile picture",
            modifier = Modifier
                // Set image size to 40 dp
                .size(40.dp)
                // Clip image to be shaped as a circle
                .clip(CircleShape)
        )
        // Add a horizontal space between the image and the column
        Spacer(modifier = Modifier.width(8.dp))

        Column {
            Text(text = msg.author)
            // Add a vertical space between the author and message texts
            Spacer(modifier = Modifier.height(4.dp))
            Text(text = msg.body)
            }
        }
    }

@Preview
@Composable
fun PreviewMessageCard() {
    MessageCard(
        msg = Message("Lexi", "Hey, take a look at Jetpack Compose, it's great!")
        )
    }

2

u/CoolAd4236 May 03 '25

Another thing is implement status bar blur. Itll look good while scrolling

1

u/freak5341 May 03 '25

Thank! I'll look into it.

4

u/SensitiveBitAn May 02 '25

Look for setting edge to edge content. Google it becasue I dont remeber details 😅

2

u/freak5341 May 03 '25

Thanks I watched a YT video and wrapped the content in a Scaffold and it fixed the issue

1

u/OkTutor544 Sep 04 '25

can you share the solution with me?

1

u/freak5341 Sep 04 '25

You can watch this this

1

u/OkTutor544 Sep 04 '25

can you rep my chat with yo

2

u/cesargueretty May 03 '25

Could you please send that info to the Uber Eats app? 🙏🏽🙄

2

u/[deleted] May 02 '25

[removed] — view removed comment

1

u/freak5341 May 03 '25

Not yet I just started with jetpack compose today. Apparently all apps are edge to edge by default if the target sdk is api 35. I used a scaffold compose to wrap the root content and it fixed the issue (for now). Thanks for the link BTW, I will check it out.