1.1简单提示框
//简单提示框
private Dialog Dialog1(){
return new AlertDialog.Builder(XXXActivity.this).setTitle("提示").setMessage("提示内容太短").show();
}
@Override
protected Dialog onCreateDialog(int id) {
if(id == 1){//两个按钮提示框
return new AlertDialog.Builder(XXXActivity.this)
.setTitle("提示").setMessage("提示内容太短")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dismissDialog(1);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dismissDialog(1);
}
}).create();
}else if(id == 2){//三个按钮提示框
return new AlertDialog.Builder(XXXActivity.this)
.setTitle("提示").setMessage("哈哈哈哈")
.setIcon(R.drawable.ic_launcher)
.setPositiveButton("注册", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setNeutralButton("找回密码", new DialogInterface.OnClickListener() {
//注意这里和下面的取消是不一样的setNeutral.....setNegative
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).create();
}else if(id ==4){ //圆形进度框
ProgressDialog dialog = new ProgressDialog(XXXActivity.this);
dialog.setTitle("正在下载歌曲...");
dialog.setMessage("请稍候......");
return dialog;
}
return super.onCreateDialog(id);
}
调用时showDialog(4);
1.3自定义对话框
命名xxxx.xml文件是我们想要自定义的风格
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
android:text="请输入..." android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<EditText android:id="@+id/testdaysnum"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
Activity调用
//自定义Dialog
LayoutInflater factory = LayoutInflater.from(XXXActivity.this);
final View testDialogView = factory.inflate(R.layout.xxxx, null);
EditText edit_GetDayNum = (EditText)testDialogView.findViewById(R.id.testdaysnum);
new AlertDialog.Builder(XXXActivity.this)
.setTitle("提示")
.setView(testDialogView)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(XXXActivity.this, "请等待...", Toast.LENGTH_LONG).show();
}
}).create().show();
1.4圆形进度框
ProgressDialog m_Dialog = ProgressDialog.show(XXXActivity.this, "请等待...", "请稍候....",true);
Toast.makeText(XXXActivity.this, "请等待...", Toast.LENGTH_LONG).show();
1.6模式对话框
Dialog dialog = new Dialog(XXXActivity.this);
Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
dialog.show();