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中创建模态对话框
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
