#StackBounty: #android #kotlin #android-dialogfragment Activity layout jumping behind statusbar, when updated from Fragment

Bounty: 50

Problem

I have an activity, where my user i as able to edit different values for an entity. I have created a BottomSheetDialogFragment, where the user is able to change some time values for said entity.

When the user changes a value (here it’s a time) i want to change the value the activity is showing in the background as well. However, when i update my activity view, the entire activity jumps behind the Statusbar like this (i know there is an inconsistency between the number picked and the number shown, it’s an timezone thing i haven’t fixed yet).

Code

The BottomSheetDialogFragment communicates to the activity through an interface called OnTimeChangedListener as so:

override fun onAttach(context: Context) {
    super.onAttach(context)
    if (context is OnTimeChangedListener) {
        listener = context
    } else {
        throw RuntimeException(context.toString() + " must implement OnTimeChangedListener")
    }
}

override fun onDetach() {
    super.onDetach()
    listener = null
}

interface OnTimeChangedListener {
    fun onTimeChanged(shift: ShiftEntity)
}

The onTimeChanged method is called when the user spins the TimePicker widget.

The method is implemented in the activity as:

override fun onTimeChanged(shift: ShiftEntity) {
    this.shift = shift
    startTimeTextView?.text = TimeFormatter.formatTime(shift.startTime, "HH:mm")
    endTimeTextView?.text = TimeFormatter.formatTime(shift.endTime, "HH:mm")
}

I’d guess the solution is somewhere in the Activitys layout file, which looks like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    android:focusableInTouchMode="true"
    tools:context=".activities.myshifts.ShiftActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            style="@style/myNavDrawer"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:background="@color/primaryBg"
            android:contentInsetEnd="0dp"
            android:contentInsetLeft="0dp"
            android:contentInsetRight="0dp"
            android:contentInsetStart="0dp"
            app:contentInsetEnd="0dp"
            app:contentInsetEndWithActions="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp"
            app:popupTheme="@style/AppTheme"
            app:theme="@style/ToolbarColoredBackArrow">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                //Content of custom AppBar goes here. Removed for an easier overview


            </android.support.constraint.ConstraintLayout>


        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

//Actual content of activity goes here. Removed it for an easier 
overview, will add if needed.

</android.support.constraint.ConstraintLayout>

Already tried

I have already tried using the android:fitsSystemWindows=”true” attribute – adding it to both the parent view and the AppBarLayout.

Adding it to the parent layout creates a padding inside of the AppBar, as soon as the Fragment opens, like seen in the top here

Adding the attribute to the AppBarLayout does not make a difference.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.