繁体   English   中英

删除 BottomSheet 的容器填充 Android

[英]Remove container padding for BottomSheet Android

BottomSheet下面有一个空间,我想是我之前隐藏的导航栏。 我想删除这个空间。 在 Layout Inspector 中,我注意到 BottomSheet 的 R.id.container (FrameLayout) 有 48dp 的填充,不知道它是什么。 尝试删除它,但它不起作用。 屏幕截图布局检查器

private void showAndHandleBottomSheetDialog() {
    final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
    bottomSheetDialog.setContentView(R.layout.bottom_sheet_dialog_layout);
    bottomSheetDialog.setCanceledOnTouchOutside(false);
    FrameLayout bottomSheet = (FrameLayout) bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
    BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
    behavior.setState(BottomSheetBehavior.STATE_EXPANDED);

    RadioGroup radioGroupTip = bottomSheetDialog.findViewById(R.id.tip_list_custom);
    ImageView buttonClose = bottomSheetDialog.findViewById(R.id.button_close);
    ArrayList<TipItem> tipItemList = new ArrayList<TipItem>(Arrays.asList(TipItem.values()));

    if (checkedButtonID != -1) {
        radioGroupTip.check(checkedButtonID);
    }

    bottomSheetDialog.show();

    buttonClose.setOnClickListener(view -> {
        checkedButtonID = radioGroupTip.getCheckedRadioButtonId();
        bottomSheetDialog.dismiss();
    });}

下面的方法将隐藏系统栏,如果你的问题的原因是导航栏那么它应该解决它。

private void showAndHandleBottomSheetDialog() {
    final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
    // here you need to inflate your view and hide system bars, then set it.
    // The added code for kotlin, kindly convert it to java
    val bottomSheetView = LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_dialog_layout,
            view?.findViewById(R.id.IdOfYourDialogParent)
        )
    bottomSheetView.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    bottomSheetDialog.setContentView(bottomSheetView);

也许你可以检查容器的父级也有填充。 我无法从代码或图片中看出问题出在哪里。

在此处输入图像描述

BottomSheetDialog 的源代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM