//先在想要底部弹窗的Activity里面创建BottomSheetDialog类
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(LoginActivity.this);
//获取你想要弹出来的界面
View bottomSheetView = getLayoutInflater().inflate(R.layout.activity_login_dialog,null);
//将弹窗的界面放入到BottomSheetDialog类中
bottomSheetDialog.setContentView(bottomSheetView);
//让弹窗显示
//bottomSheetDialog.show();
//弹窗界面组件的点击事件(我这里是按钮)
bottomSheetView.findViewById(R.id.button3).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//Activity之间的跳转
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
});
bottomSheetView.findViewById(R.id.button4).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//退出弹窗(让弹窗消失)
bottomSheetDialog.dismiss();
}
});
Android中在Activity中添加底部弹窗(BottomSheetDialog)
于 2024-05-17 16:14:47 首次发布