如何向 Android 警报对话框添加第三个按钮? [英] How can I add a third button to an Android Alert Dialog?

查看:32
本文介绍了如何向 Android 警报对话框添加第三个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

API 说 Alert Dialog 可以有一个、两个或三个按钮,但 SDK 只允许一个正负按钮.那么如何添加第三个按钮?

The API says that the Alert Dialog can have one, two or three buttons, but the SDK only allows for a positive and negative button. How then can I add a third button?

推荐答案

这段代码应该有助于解释您可以使用的三个不同的按钮:

This code snippet should help explain the three different buttons you can use:

    alertDialog = new AlertDialog.Builder(this).create();

    alertDialog.setTitle("Dialog Button");

    alertDialog.setMessage("This is a three-button dialog!");

    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Button 1 Text", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int id) {

        //...

    } }); 

    alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Button 2 Text", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int id) {

        //...

    }}); 

    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Button 3 Text", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int id) {

        //...

    }});

这篇关于如何向 Android 警报对话框添加第三个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆