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

android基础AlertDialog使用

 

     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()分别设置确定按钮的事件和取消按钮的事件。

相关文章:

  • 2021-09-20
  • 2021-12-08
  • 2021-09-02
  • 2021-06-26
  • 2021-11-12
  • 2021-07-12
猜你喜欢
  • 2021-11-09
  • 2021-09-23
  • 2021-06-20
  • 2022-12-23
  • 2021-06-08
  • 2021-11-16
  • 2021-12-09
相关资源
相似解决方案