MHo*_*gge 4 android bottom-sheet
我正在使用支持库中的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));
}
Run Code Online (Sandbox Code Playgroud)
警告是因为我使用的是 super 方法。但我该怎么办呢?我应该将我的代码移到另一个函数中(onCreateDialog(),onResume()...?),我应该删除对 super 的调用吗?
有谁知道?
我应该将代码移到另一个函数中(onCreateDialog()、onResume()...?)
是的。正如DialogFragment文档(BottomSheetDialogFragment扩展)中所示,您应该使用onCreateView()它来设置对话框。
您View从此方法返回的内容将设置为 提供的对话框的内容视图onCreateDialog()。并且getDialog()可以从内部使用该方法onCreateView()对前述内容进行任何调整Dialog。
onCreateDialog()将用于替换默认的Dialog. 在你的情况下,你可能不想这样做;考虑到该方法用于用aBottomSheetDialogFragment替换默认值(事实上,它是唯一覆盖的方法)。DialogBottomSheetDialogBottomSheetDialogFragment
以下是我创建的用于替换支持库版本的BottomSheetDialog和类(有关更多信息,请参阅评论)。BottomSheetDialogFragment
| 归档时间: |
|
| 查看次数: |
4266 次 |
| 最近记录: |