安卓:android实现弹出 AlertDialog选择提示框

本文实例为大家分享了anadroid实现弹出提示框的具体代码,供大家参考,具体内容如下

提示框是利用AlertDialog实现的

代码:(设置在button的点击事件中)

 new AlertDialog.Builder(MainActivity.this).setTitle("信息提示")//设置对话框标题

      .setMessage("是否需要更换xxx?")
      .setPositiveButton("是", new DialogInterface.OnClickListener() {//添加确定按钮

       @Override
       public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件,点击事件没写,自己添加

       }
      }).setNegativeButton("否", new DialogInterface.OnClickListener() {//添加返回按钮

     @Override
     public void onClick(DialogInterface dialog, int which) {//响应事件,点击事件没写,自己添加

     }

    }).show();//在按键响应事件中显示此对话框
   }
 });

实现效果:

安卓:android实现弹出 AlertDialog选择提示框_第1张图片

 完整代码:

package com.example.myapplicationusealertdialog

你可能感兴趣的:(安卓,android)