package com.example.hndx.myapplication
import android.content.DialogInterface
import android.os.Bundle
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Button
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Button button = (Button) findViewById(R.id.btn1)
Button button1 = (Button) findViewById(R.id.btn2)
Button button2 = (Button) findViewById(R.id.btn3)
Button button3 = (Button) findViewById(R.id.btn4)
Button button4 = (Button) findViewById(R.id.btn5)
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDialog()
}
})
}
private void showDialog(){
//android.support.v7.app.AlertDialog.Builder localBuilder = new android.support.v7.app.AlertDialog.Builder(this)
AlertDialog localBuilder =null
localBuilder =new AlertDialog.Builder(this).create()
localBuilder.setTitle("简单对话框")
localBuilder.setIcon(R.drawable.ic_launcher_foreground)
localBuilder.setMessage("提示信息?")
localBuilder.setButton(DialogInterface.BUTTON1, "确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
localBuilder.show()
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AlertDialog"/>
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="确认对话框"
android:textSize="20dp"/>
<Button
android:id="@+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="列表对话框"
android:textSize="20dp"/>
<Button
android:id="@+id/btn3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="单选对话框"
android:textSize="20dp"/>
<Button
android:id="@+id/btn4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="多选对话框"
android:textSize="20dp"/>
<Button
android:id="@+id/btn5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="自定义对话框"
android:textSize="20dp"/>
</LinearLayout>