final Context context = this; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder.setTitle("Your Title"); alertDialogBuilder .setMessage("Click yes to exit!") .setCancelable(false) .setPositiveButton("Yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity MainActivity.this.finish(); } }) .setNegativeButton("No",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } }); }
借鉴自:http://www.mkyong.com/android/android-alert-dialog-example/
相关推荐
提示框多种模式.... alertdialog
android AlertDialog对话框的类型集合 ,比较全面的讲述了 AlertDialog 的 种类 , Demo 的综合性比较强 , Demo 可直接运行
自定义AlertDialog有很多种,也有很多实现的方式,系统自带的AlertDialog往往功能单一,主要是样式比较丑,对于处女座简直是不能忍啊,于是就想到了自定义样式的AlertDialog,这里是一个简单的CustomAlertDialogDemo...
前几年的Android应用源码Demo,主要面向的是学生毕业设计学习。
Android从service定时拉起弹窗完整demo
最近项目里有个功能点,需要使用...我需要继承AlertDialog,设置自己的内容view,重写onKeyDown方法,设置dialog的位置等...... 写了个demo. Demo是在5.0手机上测试的, 6.0以上系统还需要添加动态运行时权限的逻辑 。
android记事本的demo在网上一搜一大堆,但是大神写的demo往往功能太多导致新手难以着手,很难啃得动;而一些新手写的demo又往往是东拼西凑,代码很多都是copy的别人的,直接放在项目里面用,也不知道代码有什么作用...
Basically this is a demo of how to hook in to the native camera preview screen and take a picture. The code doesn't do anything with the picture except display a AlertDialog. If you want, feel free to...
最近项目里有个功能点,需要使用定制seekbar调节媒体音量,不能使用【按物理音量上下键】弹出的系统dialog做...我需要继承AlertDialog,设置自己的内容view,重写onKeyDown方法,设置dialog的位置等...... 写了个demo
录音笔在网上的demo相比记事本就少很多了,当然在功能上与记事本相比也是大相径庭。 记事本涉及到的仅仅是对string 的存储,而且在读取上并不存在什么难点,直接用textview显示便可以了。需要做的主要是使用SQLite对...
在主流app中,应用的主界面都是底部含有多个标签的导航栏,点击可以切换到相应的界面,本demo提供功能实现,仅供参考。
安卓使用弹框做到倒计时的用法,分别使用MaterialDialog、AlertDialog来做了一个小demo
DialogFragment在android 3.0时被引入。是一种特殊的Fragment。在DialogFragment产生之前,我们创建对话框:一般采用AlertDialog和Dialog。注:官方不推荐直接使用Dialog创建对话框。
自定义AlertDialog控件,可以自定义提示框的样式、提示框页面、标题、内容、设置按钮监听、设置1到3数量的按钮。 包含demo工程和使用说明的doc
Android应用源码开发Demo,主要用于毕业设计学习。
Android应用源码开发Demo,主要用于毕业设计学习。
alertDialog简单例子,适合android初学者学习。
android倒计时器的demo,采用CountDownTimer
Android应用源码开发Demo,主要用于毕业设计学习。
android dialog 包括alertdialog 和progressdialog 还有自定义通过window 显示的界面很美观。