Android fitsSystemWindows not working when replacing fragments

前端 未结 4 432
说谎
说谎 2021-01-01 13:30

I have SingleFramgnetActivity whose purpose is only to hold and replace fragments inside it.

layout looks like this:



        
4条回答
  •  清酒与你
    2021-01-01 14:02

    Your FrameLayout is not aware of window inset sizes, because it's parent - LinearLayout hasn't dispatched him any. As a workaround, you can subclass LinearLayout and pass insets to children on your own:

    @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        int childCount = getChildCount();
        for (int index = 0; index < childCount; index++)
            getChildAt(index).dispatchApplyWindowInsets(insets); // let children know about WindowInsets
    
        return insets;
    }
    

    You can have a look to my this answer, which will explain detailed how this works, and also how to use ViewCompat.setOnApplyWindowInsetsListener API.

提交回复
热议问题