setOnApplyWindowInsetsListener() is not applying padding and calling 2 times

Viewed 580

I'm calling setOnApplyWindowInsetsListener to add padding/margin for my views. My XML contains android:fitsSystemWindows="true"

setOnApplyWindowInsetsListener after being called 2 times (on second time there insets of 0s).

Why Android returns insets twice and on the 2nd time there are zero insets value? And why my padding is not applying when I set it to the first value?

Code:

drawer.setOnApplyWindowInsetsListener((v, insets) -> {
            profileButton.setPadding(
                    profileButton.getPaddingLeft(),
                    profileButton.getPaddingTop(),
                    insets.getSystemWindowInsetBottom(),
                    profileButton.getPaddingBottom()
            );
            Timber.d("Inset applied: %d", insets.getSystemWindowInsetBottom());
            return insets;
        });

Console output:

D/MainActivity: Inset applied: 53
D/MainActivity: Inset applied: 0
0 Answers
Related