安卓之对话框

xml:




    



package com.example.my_dialog;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void onClick(View view){
        new AlertDialog.Builder(MainActivity.this).
                setTitle("对话框").setMessage("这是一个对话框").
                setPositiveButton("取消",null).
                setNeutralButton("设置",null).
                setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity.this,"确定",Toast.LENGTH_LONG).show();
                    }
                }).
                show();

    }
}

image.png
image.png

点击确定之后的情况:


image.png

你可能感兴趣的:(安卓之对话框)