Android fitsSystemWindows not working when replacing fragments

前端 未结 4 395
说谎
说谎 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:08

    You could also build a custom WindowInsetsFrameLayout and use a OnHierarchyChangedListener to request applying the insets again:

    public WindowInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    
        // Look for replaced fragments and apply the insets again.
        setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
            @Override
            public void onChildViewAdded(View parent, View child) {
                requestApplyInsets();
            }
    
            @Override
            public void onChildViewRemoved(View parent, View child) {
    
            }
        });
    }
    

    Check out this detailed answer: https://stackoverflow.com/a/47349880/3979479

提交回复
热议问题