当前位置:操作系统 > 安卓/Android >>

android基础AlertDialog使用

android中创建对话框相对来说比较简单new一个AlertDialog.Builder,然后设置它的一些信息比如显示内容,标题,是否可以通过返回键取消对话框,确定按钮,取消按钮等等。
 
  

 new AlertDialog.Builder(EX03_12.this)
            .setTitle(R.string.app_about)
            .setMessage(R.string.app_about_msg)
            .setCancelable(false)
            .setPositiveButton(R.string.str_ok,
                new DialogInterface.OnClickListener()
                {
                  public void onClick(DialogInterface dialoginterface, int i)
                  {
                  }
                })
            .setNegativeButton(R.string.str_cancel,
                new DialogInterface.OnClickListener()
                {

                  @Override
                  public void onClick(DialogInterface dialog, int which)
                  {
                    // TODO Auto-generated method stub
                    finish();
                  }
                }).show();


setCancelable(false)表示不可以通过手机上的返回键取消对话框,.setPositiveButton(),.setNegativeButton()分别设置确定按钮的事件和取消按钮的事件。

 作者  小文字

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,