My Fragment hides the Navigation Drawer?

前端 未结 2 1491
死守一世寂寞
死守一世寂寞 2021-01-27 06:43

I have a navigation Drawer in my App. If i select a particular item and slide the navigation drawer. The Fragment overlaps the navigation Drawer.

I Tried to add p

相关标签:
2条回答
  • 2021-01-27 07:26

    The following changes were made to the FloatingActionButton and FloatingActionMenu classes to allow a specific ViewGroup to be set as the container for both. Tests were made with a similar but simpler version of the code you've posted, so you may need to make adjustments to your setup parameters.

    The library code assumes that the Button and Menu are to appear on top of an Activity's content View, and everything therein. The addition of a container ViewGroup member in the FloatingActionButton class allows us to specify a child ViewGroup to be the parent instead. Please note that the following changes will only work if a FloatingActionButton is used with the Menu.

    The additions to the FloatingActionButton class:

    public class FloatingActionButton extends FrameLayout {
        ...
        private ViewGroup containerView;
        ...
        public FloatingActionButton(Activity activity, 
                                    LayoutParams layoutParams, 
                                    int theme,
                                    Drawable backgroundDrawable,
                                    int position,
                                    View contentView,
                                    FrameLayout.LayoutParams contentParams      
                                    // Note the addition of the following
                                    // constructor parameter here
                                    , ViewGroup containerView) {
            ...
            setClickable(true);
    
            // This line is new. The rest of the constructor is the same.
            this.containerView = containerView;     
    
            attach(layoutParams);
        }
        ...
        public View getActivityContentView() {
            if(containerView == null) {
                return ((Activity)getContext())
                    .getWindow().getDecorView().findViewById(android.R.id.content);
            } else {
                return containerView;
            }
        }
    
        public ViewGroup getContainerView() {
            return containerView;
        }
    
        // The following setter is not strictly necessary, but may be of use
        // if you want to toggle the Button's and Menu's z-order placement
        public void setContainerView(ViewGroup containerView) {
            this.containerView = containerView;
        }
        ...
        public static class Builder {
            ...
            private ViewGroup containerView;
            ...
            public Builder setContainerView(ViewGroup containerView) {
                this.containerView = containerView;
                return this;
            }
    
            public FloatingActionButton build() {
                return new FloatingActionButton(activity,
                                                layoutParams,
                                                theme,
                                                backgroundDrawable,
                                                position,
                                                contentView,
                                                contentParams,
                                                // New argument
                                                containerView);
            }
        }
        ...
    }
    

    And the changes to the FloatingActionMenu class:

    public class FloatingActionMenu {
        ...
        public View getActivityContentView() {
            if(mainActionView instanceof FloatingActionButton && 
                ((FloatingActionButton) mainActionView).getContainerView() != null) {
                return ((FloatingActionButton) mainActionView).getContainerView();
            } else {
                return ((Activity)mainActionView.getContext())
                    .getWindow().getDecorView().findViewById(android.R.id.content);
            }
        }
        ...
    }
    

    Then, in the Fragment's onCreateView() method, we need to add a call the new setContainerView() method of the FloatingActionButton.Builder class.

    public class HomeFragment extends Fragment {
        ...
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState)
        {
            ...
            FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(getActivity())
                .setContentView(fabIconStar, null)
                .setBackgroundDrawable(R.drawable.ic_launcher)
                .setPosition(FloatingActionButton.POSITION_TOP_CENTER)
                .setLayoutParams(starParams)
                // The new method call is added here
                .setContainerView(container)
                .build();
            ...
        }
        ...
    }
    
    0 讨论(0)
  • 2021-01-27 07:28

    Please replace the below line of code

    transaction.replace(R.id.container, Frag);
    

    with

    transaction.replace(R.id.content_frame, Frag);
    

    I had this overlapping issue once due to android.R.id.content and i replaced it with R.id.content_frame which solved my issue.

    But i see in your code that you have used a different container view ID, but this should work though.

    0 讨论(0)
提交回复
热议问题