**1;Mainactivity **
- package com.example.work1;
import android.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings(“ALL”)
public class MainActivity extends AppCompatActivity {
AlertDialog.Builder builder;
Button button1;
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
builder = new AlertDialog.Builder(this);
View inflate = LayoutInflater.from(this).inflate(R.layout.layout_dialog, null);
builder.setView(inflate);
final AlertDialog alertDialog = builder.create();
ImageView viewById1 = inflate.findViewById(R.id.tupi);
viewById1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
Button button = findViewById(R.id.buttonw);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.show();
}
});
final Button view = inflate.findViewById(R.id.tucao);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CharSequence text = view.getText();
String s = text.toString();
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
}
});
final Button view1 = inflate.findViewById(R.id.haoping);
view1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CharSequence text = view1.getText();
String s = text.toString();
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
}
});
}
}
2:布局文件
3dialog 对话框内容
4:日期对话框
对话框八种形式
1; 普通对话框
2:单选对话框
3:多选对话框
4:水平进度条对话框
5:模糊进度条对话框
6:自定义对话框
7:时间对话框
对话框 需要先创建 在展示
可以节省代码量