我想从片段中打开BottomSheetDialog。在此之前,我尝试在活动时打开BottomSheetDialog并成功。我使用相同的代码,并将getSupportFragmentManager
替换为getChildFragmentManager
。我还尝试用getActivity().getSupportFragmentManager
代替getSupportFragmentManager。有解决办法吗?
public class MainFragment extends Fragment implements BottomSheetDialog.BottomSheetListener {
private TextView mTextView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_beranda, container, false);
Button buttonOpenBottomSheet = findViewById(R.id.button_open_bottom_sheet);
buttonOpenBottomSheet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BottomSheetDialog bottomSheet = new BottomSheetDialog();
bottomSheet.show(getChildFragmentManager(),"BottomSheet");
}
});
}
}
答案 0 :(得分:0)
尝试BottomSheetDialogFragment
ModalBottomSheetDialogFragment.Builder() .add(R.menu.menu_options) .show(childFragmentManager,“ my_bottom_sheet”)