使用AlertDialog创建对话框
2014-03-26 21:34
411 查看
弹窗的制作有很多种方法,今天学习了AlertDialog的使用。代码如下:
View view;
Dialog alertDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = View.inflate(this, R.layout.exit, null);
alertDialog = new AlertDialog.Builder(this).
setTitle("对话框的标题").
setView(view).
create();
Button btnButton = (Button) findViewById(R.id.button1);
btnButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
/*Intent intent = new Intent(getApplicationContext(),Exit.class);
startActivity(intent);*/
alertDialog.show();
}
});
由于AlertDialog所以的方法都是protect的,所以我们无法直接new它的对象来使用它,我们使用它的方法就如代码所示,直接使用AlertDoalog.Builer然后用set来设置其属性。
上面的代码是一个简单的使用,其实我们可以用AlerDialog来实现很多功能,如退出程序的确认,这样的共能无非就是在弹窗上加上按钮并为其设置监听事件而已。
View view;
Dialog alertDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = View.inflate(this, R.layout.exit, null);
alertDialog = new AlertDialog.Builder(this).
setTitle("对话框的标题").
setView(view).
create();
Button btnButton = (Button) findViewById(R.id.button1);
btnButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
/*Intent intent = new Intent(getApplicationContext(),Exit.class);
startActivity(intent);*/
alertDialog.show();
}
});
由于AlertDialog所以的方法都是protect的,所以我们无法直接new它的对象来使用它,我们使用它的方法就如代码所示,直接使用AlertDoalog.Builer然后用set来设置其属性。
上面的代码是一个简单的使用,其实我们可以用AlerDialog来实现很多功能,如退出程序的确认,这样的共能无非就是在弹窗上加上按钮并为其设置监听事件而已。
相关文章推荐
- Android开发之使用AlertDialog创建对话框,单选框和多选框
- 为什么要使用AlertDialog.Builder创建AlertDialog对话框
- Adrnoid开发系列(二十五):使用AlertDialog创建各种类型的对话框
- Android使用AlertDialog创建对话框
- Adrnoid开发系列(二十五):使用AlertDialog创建各种类型的对话框
- android学习之使用AlertDialog创建对话框
- 使用AlertDialog创建对话框的大致步骤
- 使用AlertDialog类创建对话框
- 使用AlertDialog创建对话框的大致步骤
- 使用AlertDialog创建对话框
- 2.5.3 使用alertDialog创建自定义对话框
- 使用AlertDialog创建对话框
- 使用AlertDialog类创建对话框
- 使用AlertDialog创建单选列表对话框
- 使用AlertDialog创建列表对话框
- 使用AlertDialog创建简单的对话框1-显示提示消息的对话框
- alertdialog(一)——使用alertdialog创建单选列表对话框
- 使用 AlertDialog 创建列表对话框及自定义对话框
- 使用AlertDialog创建单选列表对话框
- 【Android开发】消息提示框与对话框-使用AlertDialog创建对话框