用这个
public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.content_dialog_bottom_sheet, container, false); Button btn1 = (Button)v.findViewById(R.id.btn1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(),YourActivity.class)); } }); return v; } }
然后在您的活动中调用此bottomSheet
new CustomBottomSheetDialogFragment().show(getSupportFragmentManager(), "Dialog");
而不是创建新的类,那这个怎么样
final BottomSheetDialog dialog = new BottomSheetDialog(YourActivity.this); dialog.setContentView(R.layout.your_bottomsheet_layout); dialog.setCanceledOnTouchOutside(false); ImageButton btnClose = (ImageButton) dialog.findViewById(R.id.button_close); btnClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show();