Prevent BottomSheetDialogFragment covering navigation bar

前端 未结 10 492
轮回少年
轮回少年 2020-12-12 23:49

I\'m using really naive code to show a bottom sheet dialog fragment:

class LogoutBottomSheetFragment : BottomSheetDialogFragment() {

    override fun onCrea         


        
10条回答
  •  無奈伤痛
    2020-12-13 00:36

    Use follow API to setContentView instead of overriding onCreateView.

            val dialog = BottomSheetDialog(context)
            dialog.setContentView(R.layout.your_layout)
    

    BottomSheetDialog.setContentView will setup the correct behavior for BottomSheetDialog. You can see the source code:

           public void setContentView(@LayoutRes int layoutResId) {
                  super.setContentView(this.wrapInBottomSheet(layoutResId, (View)null, (LayoutParams)null));
           }
    
           private View wrapInBottomSheet(int layoutResId, View view, LayoutParams params) {
                   FrameLayout container = (FrameLayout)View.inflate(this.getContext(), layout.design_bottom_sheet_dialog, (ViewGroup)null);
                   CoordinatorLayout coordinator = (CoordinatorLayout)container.findViewById(id.coordinator);
                   if (layoutResId != 0 && view == null) {
                      view = this.getLayoutInflater().inflate(layoutResId, coordinator, false);
                   }
                   // ... more stuff
           }
    

提交回复
热议问题