What i want to do
In BottomSheetDialogFragment, I want to inflate a view that will always adhere to the bottom of the screen, regardless of what state (collapse / expand) is BottomSheetBehavior.
What I've done
In a subclass, BottomSheetDialogFragmentI inflate a view from XML and add it as a child CoordinatorLayout(which is the BottomSheetDialogFragmentparent):
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setupBottomBar(getView());
}
private void setupBottomBar (View rootView) {
CoordinatorLayout parentView = (CoordinatorLayout) ((FrameLayout)rootView.getParent()).getParent();
parentView.addView(LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, parentView, false), -1);
}
The code works without errors.
And when I use the Layout Inspector to view the View hierarchy, the view structure is also correct:

You can also download the result of the layout inspector here and open it using your own Android studio.
Problem
, CoordinatorLayout, BottomSheetDialogFragment.
BottomSheetDialogFragemnt ( ), , .

?
@GoodDev, , (design_bottom_sheet) Z BottomSheetDialog.
, , Z.
- Z design_bottom_sheet .
private void setupBottomBar (View rootView) {
CoordinatorLayout parentView = (CoordinatorLayout) (rootView.getParent().getParent());
View barView = LayoutInflater.from(getContext()).inflate(R.layout.item_selection_bar, parentView, false);
ViewCompat.setTranslationZ(barView, ViewCompat.getZ((View)rootView.getParent()));
parentView.addView(barView, -1);
}