gpt4 book ai didi

android - BottomSheetDialogFragment setupDialog 仅限于库组

转载 作者:行者123 更新时间:2023-11-29 19:05:50 25 4
gpt4 key购买 nike

我正在使用 BottomSheetDialogFragment来自支持库,它警告我函数 setupDialog() 应该只在库组中使用。但是这个函数是我初始化对话框的地方:

@Override
public void setupDialog(final Dialog dialog, int style) {
super.setupDialog(dialog, style);
FragmentArgs.inject(this);

dialog.setOnShowListener(dialogINterface -> {
if(dialog.getWindow() != null) {
dialog.getWindow().setLayout(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT);
}
});

BottomSheetStatisticsExportBinding binding = DataBindingUtil.inflate(
LayoutInflater.from(getContext()),
R.layout.bottom_sheet_statistics_export,
null,
false
);

View contentView = binding.getRoot();
dialog.setContentView(contentView);

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
CoordinatorLayout.Behavior behavior = params.getBehavior();

if( behavior != null && behavior instanceof BottomSheetBehavior )
((BottomSheetBehavior) behavior).setBottomSheetCallback(bottomSheetBehaviorCallback);

for (Export export : exports)
binding.flexbox.addView(new ExportItemView(getContext(), export));
}

警告是因为我正在使用 super 方法。但是我应该怎么做呢?我是否应该将我的代码移到另一个函数中(onCreateDialog()onResume()...?),我是否应该删除对 super 的调用?

有人知道吗?

最佳答案

Should I move my code inside another function (onCreateDialog(), onResume()...?)

是的。正如它在 DialogFragment documentation 中所展示的那样(BottomSheetDialogFragment 扩展),您应该使用 onCreateView() 来设置您的对话框。

您从此方法返回的View 将被设置为onCreateDialog() 提供的对话框的内容 View 。并且可以在 onCreateView() 中使用 getDialog() 方法对上述 Dialog 进行任何调整。


onCreateDialog() 将用于替换默认的 Dialog。在您的情况下,您可能不想这样做;考虑到这是 BottomSheetDialogFragment 用来用 BottomSheetDialog 替换默认 Dialog 的方法(事实上,它是唯一的方法 BottomSheetDialogFragment 覆盖)。


Here是我创建的用于替换支持库版本的 BottomSheetDialogBottomSheetDialogFragment 类(有关详细信息,请参阅评论)。

关于android - BottomSheetDialogFragment setupDialog 仅限于库组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47267301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com