Trying to understand edge to edge in Android

After updating my SDK to version 35, I noticed that my app’s UI now starts directly from the top of the display, including behind the status bar. Previously, the design started below the status bar. To understand how edge-to-edge functionality works, I created a sample layout.

The XML layout I am using is as follows:

xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity"
    android:id="@+id/main">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize" />
    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="@dimen/fab_margin"
        android:layout_marginBottom="16dp"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

With android:fitsSystemWindows="true", my output looks like this:

In this case, the status bar and AppBarLayout share the same color.

However, when I change android:fitsSystemWindows to "false" and use the following code in my activity:

ViewCompat.setOnApplyWindowInsetsListener(
    findViewById<View>(R.id.main)
) { v: View, insets: WindowInsetsCompat ->
    val systemBars: Insets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
    v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
    insets
}

I get a different result:

Now the status bar and AppBarLayout have different colors.

This confuses me. When I set android:fitsSystemWindows="true" in XML, the status bar and AppBarLayout are the same color. But when I handle the insets programmatically, the colors are different. I tried setting the status bar color with this.getWindow().setStatusBarColor, but it no longer works from Android 15 (SDK 35). I also tried using the following code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.insetsController?.setSystemBarsAppearance(
        APPEARANCE_LIGHT_STATUS_BARS, // For light status bar icons
        APPEARANCE_LIGHT_STATUS_BARS
    )
} else {
    @Suppress("DEPRECATION")
    window.decorView.systemUiVisibility =
        window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR // For light status bar icons
}

But the status bar color still doesn’t change.

Questions:

  1. Why is edge-to-edge functionality mandatory?
  2. How do I properly implement edge-to-edge in a regular Android app (non-gaming)?
  3. What are the potential side effects of using edge-to-edge, such as issues with height calculations?
  4. Need solution for my issue.

I would appreciate any help on this.


Why is edge-to-edge functionality mandatory?

Yes, Android 15 enforces edge-to-edge Before target SDK 35 (Android 15), your app does not draw edge-to-edge without explicit code changes to intentionally go edge-to-edge. After setting targetSdk=35 or higher, the system will draw your app edge-to-edge by default on Android 15 and later devices.

How do I properly implement edge-to-edge in a regular Android app (non-gaming)?

For apps targeting Android 15 : By default, your app will draw behind system bars, enabling edge-to-edge. You may need to handle insets as described below.

For apps targeting older Android versions:

  • You’ll need to manually opt-in:

WindowCompat.setDecorFitsSystemWindows(window, false) in your Activity’s onCreate() method. This makes the window layout handle system windows (status bar, navigation bar) instead of your content.

ViewCompat.setOnApplyWindowInsetsListener(view) { v, insets ->
         val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
         // Apply padding or margins based on systemBarsInsets 
         v.updatePadding(top = systemBarsInsets.top, 
                         bottom = systemBarsInsets.bottom,
                         left = systemBarsInsets.left,
                         right = systemBarsInsets.right) 
         insets // or insets.consumeSystemWindowInsets()
     }

If you are using Material Design Components, they often have built-in support for edge-to-edge:

  • AppBarLayout: Use app:layout_insetEdge="top" and the appropriate
    fitsSystemWindows settings to ensure it extends behind the status
    bar.
  • DrawerLayout: Similar to AppBarLayout, adjust its layout behavior.
  • BottomNavigationView: Use app:layout_insetEdge="bottom" and adjust
    margins or padding to avoid overlapping the navigation bar.
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        WindowCompat.setDecorFitsSystemWindows(window, false) 

        // Example: Applying insets to a content view
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.my_content_view)) { v, insets ->
            val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.updatePadding(top = systemBarsInsets.top, bottom = systemBarsInsets.bottom)
            insets 
        }
    }
}

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật