1

I try to show an ImageView behing the statusbar. It's working using window.setDecorFitsSystemWindows(false) with android R minimum :

This is my style (using NoActionBar and setting the statusbar color to transparent) :

<style name="Theme.TestProject" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <item name="android:statusBarColor" tools:targetApi="l">#80000000</item>
    </style>

My layout :

<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:scaleType="centerCrop"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/nature" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="First button"
        app:layout_constraintBottom_toTopOf="@+id/button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />


    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Second button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

This is the result : The result

It's good in the top but in the bottom, my view is truncated so I see only one button. Why ?

Jéwôm'
  • 3,753
  • 5
  • 40
  • 73
  • Since you've disabled [`setDecorFitsSystemWindows`](https://developer.android.com/reference/android/view/Window#setDecorFitsSystemWindows(boolean)) your decor window doesn't handle system insets. You have to do it yourself by adding [`View.OnApplyWindowInsetsListener`](https://developer.android.com/reference/android/view/View.OnApplyWindowInsetsListener) to your`ConstraintLayout` and "consume" system insets there (for example add bottom padding equal to navigation bar size). – Pawel Aug 23 '21 at 19:47
  • Thanks @Pawel but there is not a way to get the same result without adding a bottom padding? There is no a method for this? – Jéwôm' Aug 24 '21 at 06:57
  • You can try some other stuff like wrap your layout with `CoordinatorLayout` or add `fitSystemWindows=true` on your root layout but those methods internally do just that - add padding equal to system insets so content of your app is not drawn below them. – Pawel Aug 24 '21 at 09:12
  • @Pawel `fitSystemWindows=true` doesn't help and just produces weird behavior of bottom sheet. I just want my layout to be able to draw behind status bar but bottom navigation panel should as usual (don't draw behind it) – user924 Aug 14 '22 at 13:08
  • @Jéwôm' how did you solve it? – user924 Aug 14 '22 at 13:32

0 Answers0