How to create modal dialog box in android(如何在android中创建模态对话框)
问题描述
我想为我的应用程序创建模式对话框.
i want create modal dialog box for my application.
所以当模态对话框打开时,其他活动被阻止.没有像按下后退按钮或按下主页按钮那样完成任何事件.
so when modal dialog box open the other activities are blocked. no event are done like back button press or home button press.
并在该对话框中放置两个选项按钮取消并确定.
and put two option button in that dialog box cancel and ok.
谢谢...
推荐答案
Android中有很多种Dialogs.请查看 对话框.我猜你正在寻找类似 AlertDialog 的东西.这是如何在 BackPress 按钮上实现的示例.
There are many kind of Dialogs in Android. Please take a look at Dialogs. I guess what you are looking for is something like AlertDialog . This is the example of how you can implement on BackPress button.
@Override
public void onBackPressed() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Do you want to logout?");
// alert.setMessage("Message");
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//Your action here
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
这篇关于如何在android中创建模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在android中创建模态对话框
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
