【问题标题】:want to create BottomSheetDialogFragment Like Atttache One想像附件一一样创建BottomSheetDialogFragment
【发布时间】:2021-12-06 09:35:29
【问题描述】:

我希望我的底页在默认、拖动和关闭等阶段表现得像附加图像。

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: android android-bottomsheetdialog bottomsheetdialogfragment


【解决方案1】:

这是一个例子:

 public class ExampleFragment extends BottomSheetDialogFragment {
  
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_pdf_view, container, false);
         //Views
         
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public int getTheme() {
        return R.style.AppBottomSheetDialogTheme;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                BottomSheetDialog d = (BottomSheetDialog) dialog;
                FrameLayout bottomSheet = d.findViewById(R.id.design_bottom_sheet);
                BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
            }
        });

        // Do something with your dialog like setContentView() or whatever
        return dialog;
    }
 
   }

【讨论】:

  • 对话框应该只在点击顶部图像而不是对话框时拖动。你能提供完整的例子吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-16
相关资源
最近更新 更多