zl程序教程

您现在的位置是:首页 >  其它

当前栏目

setPositiveButton和setNegativeButton的区别[通俗易懂]

通俗易懂 区别
2023-06-13 09:12:10 时间

大家好,又见面了,我是你们的朋友全栈君。

setPositiveButton和setNegativeButton的区别和setNeutralButton的区别

三者都是AlertDialog弹出框的按钮,都是封装好的button,只是显示的位置不同,项目中可根据情况选择使用,setNegativeButton一般用于确认,setNegativeButton一般用于取消。

new AlertDialog.Builder(MainActivity.this)
            .setTitle("dialog")
            .setMessage("三者的区别")
            .setPositiveButton("positive", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            })
            .setNegativeButton("negative", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            })
            .setNeutralButton("neutral", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {

                }
            })
            .show();

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148512.html原文链接:https://javaforall.cn